Class: Sidekiq::Control::Worker::Instance

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/control/worker/instance.rb

Constant Summary collapse

UnsupportedJobType =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job) ⇒ Instance

Returns a new instance of Instance.

Parameters:

  • job (Class)


12
13
14
# File 'lib/sidekiq/control/worker/instance.rb', line 12

def initialize(job)
  @job = job
end

Instance Attribute Details

#jobObject (readonly)

Returns the value of attribute job.



9
10
11
# File 'lib/sidekiq/control/worker/instance.rb', line 9

def job
  @job
end

Instance Method Details

#nameObject



16
17
18
# File 'lib/sidekiq/control/worker/instance.rb', line 16

def name
  job.name
end

#other_perform_methodsObject



28
29
30
# File 'lib/sidekiq/control/worker/instance.rb', line 28

def other_perform_methods
  @other_perform_methods ||= job.singleton_methods(false).select { |m| m.to_s.start_with?('perform') }
end

#paramsObject



20
21
22
# File 'lib/sidekiq/control/worker/instance.rb', line 20

def params
  @params ||= worker_params.map { |e| Param.new(*e) }
end

#queueObject



24
25
26
# File 'lib/sidekiq/control/worker/instance.rb', line 24

def queue
  @queue ||= sidekiq_job? ? job.get_sidekiq_options['queue'] : job.queue_name
end

#trigger(params, job_queue = nil) ⇒ Object



32
33
34
# File 'lib/sidekiq/control/worker/instance.rb', line 32

def trigger(params, job_queue=nil)
  trigger_in(0, params, job_queue)
end

#trigger_in(seconds, params, job_queue = nil) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/sidekiq/control/worker/instance.rb', line 36

def trigger_in(seconds, params, job_queue=nil)
  if sidekiq_job?
    Sidekiq::Client.enqueue_to_in(job_queue || queue, seconds, job, *params)
  elsif active_job?
    job.set(wait: seconds, queue: job_queue || queue).perform_later(*params)
  else
    raise UnsupportedJobType
  end
end