class Resque::Worker::Heart
Attributes
worker[R]
Public Class Methods
heartbeat_interval_seconds()
click to toggle source
# File lib/resque/heartbeat.rb, line 51 def self.heartbeat_interval_seconds ENV['HEARTBEAT_INTERVAL_SECONDS'] || 2 end
heartbeat_key(worker_name, pid)
click to toggle source
you can send a redis wildcard to filter the workers you’re looking for
# File lib/resque/heartbeat.rb, line 88 def Heart.heartbeat_key(worker_name, pid) "worker:#{worker_name}:#{pid}:heartbeat" end
heartbeats_before_dead()
click to toggle source
# File lib/resque/heartbeat.rb, line 55 def self.heartbeats_before_dead ENV['HEARTBEATS_BEFORE_DEAD'] || 25 end
new(worker)
click to toggle source
# File lib/resque/heartbeat.rb, line 60 def initialize(worker) @worker = worker end
Public Instance Methods
beat!()
click to toggle source
# File lib/resque/heartbeat.rb, line 96 def beat! redis.sadd(:workers, worker) redis.setex(key, Heart.heartbeat_interval_seconds * Heart.heartbeats_before_dead, '') rescue Exception => e Resque.logger.fatal "Unable to set the heartbeat for worker '#{worker.remote_hostname}:#{worker.remote_pid}': #{e} : #{e.backtrace}" end
dead?()
click to toggle source
# File lib/resque/heartbeat.rb, line 103 def dead? !redis.exists(key) end
key()
click to toggle source
# File lib/resque/heartbeat.rb, line 92 def key Heart.heartbeat_key(worker.remote_hostname, worker.remote_pid) end
redis()
click to toggle source
# File lib/resque/heartbeat.rb, line 83 def redis Resque.redis end
run()
click to toggle source
# File lib/resque/heartbeat.rb, line 64 def run @thrd ||= Thread.new do loop do begin beat! && sleep(Heart.heartbeat_interval_seconds) rescue Exception => e Resque.logger.error "Error while doing heartbeat: #{e} : #{e.backtrace}" end end end end
stop()
click to toggle source
# File lib/resque/heartbeat.rb, line 76 def stop Thread.kill(@thrd) if @thrd redis.del key rescue nil end
ttl()
click to toggle source
# File lib/resque/heartbeat.rb, line 107 def ttl Resque.redis.ttl key end