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).
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
49 50 51 |
# File 'lib/sidekiq/worker.rb', line 49 def perform_async(*args) @klass.client_push(@opts.merge('args'.freeze => args, 'class'.freeze => @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).
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/sidekiq/worker.rb', line 55 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'.freeze => @klass, 'args'.freeze => args, 'at'.freeze => ts) # Optimization to enqueue something now that is scheduled to go out now or in the past payload.delete('at'.freeze) if ts <= now @klass.client_push(payload) end |