class Sidekiq::Worker::Setter
This helper class encapsulates the set options for `set`, e.g.
SomeWorker.set(queue: 'foo').perform_async(....)
Public Class Methods
new(klass, opts)
click to toggle source
# File lib/sidekiq/worker.rb, line 44 def initialize(klass, opts) @klass = klass @opts = opts end
Public Instance Methods
perform_async(*args)
click to toggle source
# 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)
click to toggle source
interval
must be a timestamp, numeric or something that acts
numeric (like an activesupport time interval).
# 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
Also aliased as: perform_at
set(options)
click to toggle source
# File lib/sidekiq/worker.rb, line 49 def set(options) @opts.merge!(options) self end