Skip to content
Mike Perham edited this page Jul 19, 2016 · 5 revisions

In Sidekiq, a Worker is a class that executes jobs based on the arguments passed into its perform method.

class MyWorker
  include Sidekiq::Worker

  def perform(user_id : Int64, email : String)
    # do something
  end
end

You create a job using the async API:

jid = MyWorker.async.perform(123_i64, "hello@example.com")

You'll get back a JID, a unique identifier for every job you create.

Configuration

Statically

You can use sidekiq_options to declare custom options for each Worker.

class MyWorker
  include Sidekiq::Worker
  sidekiq_options do |job|
    job.queue = "foo"
    job.retry = false
  end

  def perform(...)
    ...
  end
end

Dynamically

You can dynamically configure the properties of a job using the block form of async:

jid = MyWorker.async do |job|
  job.queue = "foo"
  job.retry = false
end.perform(123_i64, "hello@example.com")
Clone this wiki locally