Class: SidekiqAlive::Worker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
lib/sidekiq_alive/worker.rb

Instance Method Summary collapse

Instance Method Details

#configObject



41
42
43
# File 'lib/sidekiq_alive/worker.rb', line 41

def config
  SidekiqAlive.config
end

#current_hostnameObject



37
38
39
# File 'lib/sidekiq_alive/worker.rb', line 37

def current_hostname
  SidekiqAlive.hostname
end

#hostname_registered?(hostname) ⇒ Boolean

Returns:

  • (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



8
9
10
11
12
13
14
15
16
# File 'lib/sidekiq_alive/worker.rb', line 8

def perform(_hostname = SidekiqAlive.hostname)
  # Checks if custom liveness probe passes should fail or return false
  return unless config.custom_liveness_probe.call

  # Writes the liveness in Redis
  write_living_probe
  # schedules next living probe
  self.class.perform_in(config.time_to_live / 2, current_hostname)
end

#write_living_probeObject



24
25
26
27
28
29
30
31
32
33
34
35
# 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
  begin
    config.callback.call
  rescue StandardError
    nil
  end
end