Module: SwitchmanInstJobs::Delayed::Worker::HealthCheck::ClassMethods

Defined in:
lib/switchman_inst_jobs/delayed/worker/health_check.rb

Instance Method Summary collapse

Instance Method Details

#munge_service_name(shard) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/switchman_inst_jobs/delayed/worker/health_check.rb', line 10

def munge_service_name(shard)
  # munge the name to add the current shard
  original_service_name = ::Delayed::Settings.worker_health_check_config['service_name']
  consul_service_name = ::Delayed::Worker::ConsulHealthCheck::DEFAULT_SERVICE_NAME
  ::Delayed::Settings.worker_health_check_config['service_name'] =
    "#{original_service_name || consul_service_name}/#{shard.id}"
  yield
ensure
  ::Delayed::Settings.worker_health_check_config['service_name'] = original_service_name
end

#reschedule_abandoned_jobs(call_super: false) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/switchman_inst_jobs/delayed/worker/health_check.rb', line 21

def reschedule_abandoned_jobs(call_super: false)
  shards = ::Switchman::Shard.delayed_jobs_shards.to_a
  call_super = shards.first if shards.length == 1
  unless call_super == false
    call_super.activate(:delayed_jobs) do
      return munge_service_name(call_super) { super() }
    end
  end

  ::Switchman::Shard.with_each_shard(shards, [:delayed_jobs], exception: :ignore) do
    shard = ::Switchman::Shard.current(:delayed_jobs)
    singleton = <<~SINGLETON
      periodic: Delayed::Worker::HealthCheck.reschedule_abandoned_jobs:#{shard.id}
    SINGLETON
    delay(singleton: singleton).reschedule_abandoned_jobs(call_super: shard)
  end
end