Class: SidekiqAlive::Worker
- Inherits:
-
Object
- Object
- SidekiqAlive::Worker
- Includes:
- Sidekiq::Worker
- Defined in:
- lib/sidekiq_alive/worker.rb
Instance Method Summary collapse
- #config ⇒ Object
- #current_hostname ⇒ Object
- #hostname_registered?(hostname) ⇒ Boolean
- #perform(hostname = SidekiqAlive.hostname) ⇒ Object
- #write_living_probe ⇒ Object
Instance Method Details
#config ⇒ Object
37 38 39 |
# File 'lib/sidekiq_alive/worker.rb', line 37 def config SidekiqAlive.config end |
#current_hostname ⇒ Object
33 34 35 |
# File 'lib/sidekiq_alive/worker.rb', line 33 def current_hostname SidekiqAlive.hostname end |
#hostname_registered?(hostname) ⇒ Boolean
18 19 20 21 22 |
# File 'lib/sidekiq_alive/worker.rb', line 18 def hostname_registered?(hostname) SidekiqAlive.registered_instances.any? do |ri| /#{hostname}/ =~ ri end end |
#perform(hostname = SidekiqAlive.hostname) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/sidekiq_alive/worker.rb', line 6 def perform(hostname = SidekiqAlive.hostname) return unless hostname_registered?(hostname) if current_hostname == hostname write_living_probe # schedule next living probe self.class.perform_in(config.time_to_live / 2, current_hostname) else # requeue for hostname to validate it's own liveness probe self.class.perform_async(hostname) end end |
#write_living_probe ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/sidekiq_alive/worker.rb', line 24 def write_living_probe # Write liveness probe SidekiqAlive.store_alive_key # Increment ttl for current registered instance SidekiqAlive.register_current_instance # after callbacks config.callback.call() end |