Class: CI::Queue::Redis::Base::HeartbeatProcess
- Inherits:
-
Object
- Object
- CI::Queue::Redis::Base::HeartbeatProcess
- Defined in:
- lib/ci/queue/redis/base.rb
Instance Method Summary collapse
- #boot! ⇒ Object
-
#initialize(redis_url, zset_key, processed_key, owners_key, worker_queue_key) ⇒ HeartbeatProcess
constructor
A new instance of HeartbeatProcess.
- #shutdown! ⇒ Object
- #tick!(id) ⇒ Object
Constructor Details
#initialize(redis_url, zset_key, processed_key, owners_key, worker_queue_key) ⇒ HeartbeatProcess
Returns a new instance of HeartbeatProcess.
216 217 218 219 220 221 222 |
# File 'lib/ci/queue/redis/base.rb', line 216 def initialize(redis_url, zset_key, processed_key, owners_key, worker_queue_key) @redis_url = redis_url @zset_key = zset_key @processed_key = processed_key @owners_key = owners_key @worker_queue_key = worker_queue_key end |
Instance Method Details
#boot! ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/ci/queue/redis/base.rb', line 224 def boot! child_read, @pipe = IO.pipe ready_pipe, child_write = IO.pipe @pipe.binmode @pid = Process.spawn( RbConfig.ruby, ::File.join(__dir__, "monitor.rb"), @redis_url, @zset_key, @processed_key, @owners_key, @worker_queue_key, in: child_read, out: child_write, ) child_read.close child_write.close # Check the process is alive. if ready_pipe.wait_readable(10) ready_pipe.gets ready_pipe.close Process.kill(0, @pid) else Process.kill(0, @pid) Process.wait(@pid) raise "Monitor child wasn't ready after 10 seconds" end @pipe end |
#shutdown! ⇒ Object
255 256 257 258 259 260 261 262 263 |
# File 'lib/ci/queue/redis/base.rb', line 255 def shutdown! @pipe.close begin _, status = Process.waitpid2(@pid) status rescue Errno::ECHILD nil end end |
#tick!(id) ⇒ Object
265 266 267 |
# File 'lib/ci/queue/redis/base.rb', line 265 def tick!(id) (:tick!, id: id) end |