Class: Resque::Worker
- Inherits:
-
Object
- Object
- Resque::Worker
- Defined in:
- lib/resque/heartbeat.rb
Instance Method Summary collapse
- #heartbeat! ⇒ Object
-
#heartbeat_redis ⇒ Object
apparently the Redis connection is not thread-safe, so we connect another instance see github.com/ezmobius/redis-rb/issues#issue/75.
- #last_heartbeat ⇒ Object
- #last_heartbeat_before?(seconds) ⇒ Boolean
- #startup_with_heartbeat ⇒ Object (also: #startup)
Instance Method Details
#heartbeat! ⇒ Object
32 33 34 35 36 37 |
# File 'lib/resque/heartbeat.rb', line 32 def heartbeat! heartbeat_redis.sadd(:workers, self) heartbeat_redis.set("worker:#{self}:heartbeat", Time.now.to_s) rescue Exception => e p e end |
#heartbeat_redis ⇒ Object
apparently the Redis connection is not thread-safe, so we connect another instance see github.com/ezmobius/redis-rb/issues#issue/75
25 26 27 28 29 30 |
# File 'lib/resque/heartbeat.rb', line 25 def heartbeat_redis @heartbeat_redis ||= begin redis = Redis.connect(:url => Travis.config['redis']['url']) Redis::Namespace.new(:resque, :redis => redis) end end |
#last_heartbeat ⇒ Object
43 44 45 |
# File 'lib/resque/heartbeat.rb', line 43 def last_heartbeat redis.get("worker:#{self}:heartbeat") || started end |
#last_heartbeat_before?(seconds) ⇒ Boolean
39 40 41 |
# File 'lib/resque/heartbeat.rb', line 39 def last_heartbeat_before?(seconds) Time.parse(last_heartbeat).utc < (Time.now.utc - seconds) end |
#startup_with_heartbeat ⇒ Object Also known as: startup
11 12 13 14 15 16 17 18 19 |
# File 'lib/resque/heartbeat.rb', line 11 def startup_with_heartbeat startup_without_heartbeat Thread.new do loop do sleep(2) heartbeat! end end end |