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(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(opts) ⇒ Setter
Returns a new instance of Setter.
44 45 46 |
# File 'lib/sidekiq/worker.rb', line 44 def initialize(opts) @opts = opts end |
Instance Method Details
#perform_async(*args) ⇒ Object
48 49 50 |
# File 'lib/sidekiq/worker.rb', line 48 def perform_async(*args) @opts['class'.freeze].client_push(@opts.merge!('args'.freeze => args)) 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).
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/sidekiq/worker.rb', line 54 def perform_in(interval, *args) int = interval.to_f now = Time.now.to_f ts = (int < 1_000_000_000 ? now + int : int) @opts.merge! 'args'.freeze => args, 'at'.freeze => ts # Optimization to enqueue something now that is scheduled to go out now or in the past @opts.delete('at'.freeze) if ts <= now @opts['class'.freeze].client_push(@opts) end |