Method: Sidekiq::Client#push
- Defined in:
- lib/sidekiq/client.rb
#push(item) ⇒ Object
The main method used to push a job to Redis. Accepts a number of options:
queue - the named queue to use, default 'default'
class - the job class to call, required
args - an array of simple arguments to the perform method, must be JSON-serializable
at - timestamp to schedule the job (optional), must be Numeric (e.g. Time.now.to_f)
retry - whether to retry this job if it fails, default true or an integer number of retries
retry_for - relative amount of time to retry this job if it fails, default nil
backtrace - whether to save any error backtrace, default false
If class is set to the class name, the jobs’ options will be based on Sidekiq’s default job options. Otherwise, they will be based on the job class’s options.
Any options valid for a job class’s sidekiq_options are also available here.
All keys must be strings, not symbols. NB: because we are serializing to JSON, all symbols in ‘args’ will be converted to strings. Note that backtrace: true can take quite a bit of space in Redis; a large volume of failing jobs can start Redis swapping if you aren’t careful.
Returns a unique Job ID. If middleware stops the job, nil will be returned instead.
Example:
push('queue' => 'my_queue', 'class' => MyJob, 'args' => ['foo', 1, :bat => 'bar'])
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/sidekiq/client.rb', line 101 def push(item) normed = normalize_item(item) payload = middleware.invoke(item["class"], normed, normed["queue"], @redis_pool) do normed end if payload verify_json(payload) raw_push([payload]) payload["jid"] end end |