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 43
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 53
def perform_async(*args)
  @klass.client_push(@opts.merge('args' => args, 'class' => @klass))
end
perform_at(interval, *args)
Alias for: perform_in
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 59
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 48
def set(options)
  @opts.merge!(options)
  self
end