Module: SwitchmanInstJobs::Delayed::Worker

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

Defined Under Namespace

Modules: ClassMethods, HealthCheck

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object



4
5
6
# File 'lib/switchman_inst_jobs/delayed/worker.rb', line 4

def self.prepended(base)
  base.singleton_class.prepend(ClassMethods)
end

Instance Method Details

#initialize(options = {}) ⇒ Object



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

def initialize(options = {})
  # have to initialize this first, so #shard works
  @config = options
  ::Delayed::Worker::HealthCheck.munge_service_name(shard) do
    super
    # ensure we get our own copy of the munged config
    @health_check_config = @health_check_config.dup
  end
end

#runObject

Worker#run is usually only called from Worker#start, but if the worker is called directly from the console, we want to make sure it still gets the right shard activated.



25
26
27
# File 'lib/switchman_inst_jobs/delayed/worker.rb', line 25

def run
  shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) { super }
end

#shardObject



29
30
31
# File 'lib/switchman_inst_jobs/delayed/worker.rb', line 29

def shard
  self.class.shard(@config[:shard])
end

#startObject



18
19
20
# File 'lib/switchman_inst_jobs/delayed/worker.rb', line 18

def start
  shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) { super }
end