Class: Sidekiq::Control::Worker::Instance
- Inherits:
-
Object
- Object
- Sidekiq::Control::Worker::Instance
- Defined in:
- lib/sidekiq/control/worker/instance.rb
Constant Summary collapse
- UnsupportedJobType =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#job ⇒ Object
readonly
Returns the value of attribute job.
Instance Method Summary collapse
-
#initialize(job) ⇒ Instance
constructor
A new instance of Instance.
- #name ⇒ Object
- #other_perform_methods ⇒ Object
- #params ⇒ Object
- #queue ⇒ Object
- #trigger(params, job_queue = nil) ⇒ Object
- #trigger_in(seconds, params, job_queue = nil) ⇒ Object
Constructor Details
#initialize(job) ⇒ Instance
Returns a new instance of Instance.
12 13 14 |
# File 'lib/sidekiq/control/worker/instance.rb', line 12 def initialize(job) @job = job end |
Instance Attribute Details
#job ⇒ Object (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
#name ⇒ Object
16 17 18 |
# File 'lib/sidekiq/control/worker/instance.rb', line 16 def name job.name end |
#other_perform_methods ⇒ Object
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 |
#params ⇒ Object
20 21 22 |
# File 'lib/sidekiq/control/worker/instance.rb', line 20 def params @params ||= worker_params.map { |e| Param.new(*e) } end |
#queue ⇒ Object
24 25 26 |
# File 'lib/sidekiq/control/worker/instance.rb', line 24 def queue @queue ||= sidekiq_job? ? job.['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 |