Class: Sidekiq::PowerFetch::Heartbeat
- Inherits:
-
Object
- Object
- Sidekiq::PowerFetch::Heartbeat
- Defined in:
- lib/sidekiq/power_fetch/heartbeat.rb
Constant Summary collapse
- LIFESPAN =
seconds
60
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(config) ⇒ Heartbeat
constructor
A new instance of Heartbeat.
- #pulse ⇒ Object
Constructor Details
#initialize(config) ⇒ Heartbeat
Returns a new instance of Heartbeat.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/sidekiq/power_fetch/heartbeat.rb', line 20 def initialize(config) raise "#{self.class} already started" if self.class.started? @config = config # Must pulse on startup, else races: other workers think the current # process is dead, but it just didn't heartbeat yet. @config.on(:startup) { pulse } @config.on(:heartbeat) { pulse } self.class.started = true end |
Class Method Details
.key(identity) ⇒ Object
32 33 34 35 |
# File 'lib/sidekiq/power_fetch/heartbeat.rb', line 32 def self.key(identity) id = identity.tr(":", "-") "sidekiq-power-fetch-heartbeat-#{id}" end |
.start(config) ⇒ Object
8 9 10 |
# File 'lib/sidekiq/power_fetch/heartbeat.rb', line 8 def self.start(config) new(config) end |
.started=(value) ⇒ Object
16 17 18 |
# File 'lib/sidekiq/power_fetch/heartbeat.rb', line 16 def self.started=(value) @started = value end |
.started? ⇒ Boolean
12 13 14 |
# File 'lib/sidekiq/power_fetch/heartbeat.rb', line 12 def self.started? @started end |
Instance Method Details
#pulse ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/sidekiq/power_fetch/heartbeat.rb', line 37 def pulse @config.redis do |conn| conn.set(key, 1, ex: LIFESPAN) end @config.logger.debug("[PowerFetch] Heartbeat for #{PowerFetch.identity}") end |