Class: Sidekiq::Worker::Setter
- Inherits:
-
Object
- Object
- Sidekiq::Worker::Setter
- Defined in:
- lib/sidekiq/worker.rb
Overview
This helper class encapsulates the set options for ‘set`, e.g.
SomeWorker.set(queue: 'foo').perform_async(....)
Instance Method Summary collapse
-
#initialize(klass, opts) ⇒ Setter
constructor
A new instance of Setter.
- #perform_async(*args) ⇒ Object
-
#perform_in(interval, *args) ⇒ Object
(also: #perform_at)
interval
must be a timestamp, numeric or something that acts numeric (like an activesupport time interval). - #set(options) ⇒ Object
Constructor Details
#initialize(klass, opts) ⇒ Setter
Returns a new instance of Setter.
44 45 46 47 |
# File 'lib/sidekiq/worker.rb', line 44 def initialize(klass, opts) @klass = klass @opts = opts end |
Instance Method Details
#perform_async(*args) ⇒ Object
54 55 56 |
# File 'lib/sidekiq/worker.rb', line 54 def perform_async(*args) @klass.client_push(@opts.merge('args' => args, 'class' => @klass)) end |
#perform_in(interval, *args) ⇒ Object Also known as: perform_at
interval
must be a timestamp, numeric or something that acts
numeric (like an activesupport time interval).
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/sidekiq/worker.rb', line 60 def perform_in(interval, *args) int = interval.to_f now = Time.now.to_f ts = (int < 1_000_000_000 ? now + int : int) payload = @opts.merge('class' => @klass, 'args' => args, 'at' => ts) # Optimization to enqueue something now that is scheduled to go out now or in the past payload.delete('at') if ts <= now @klass.client_push(payload) end |
#set(options) ⇒ Object
49 50 51 52 |
# File 'lib/sidekiq/worker.rb', line 49 def set() @opts.merge!() self end |