Published 17/03/2019
Last Updated 18/11/2024

References

ActiveJob

Config Sidekiq as queue adapter

class Application < Rails::Application
  # ...
  config.active_job.queue_adapter = :sidekiq
end

An example job

class ExampleJob < ActiveJob::Base
  queue_as :default
  # Available for Sidekiq 6.0.1+ and Rails 6.0.1+
  sidekiq_options retry: 5

  def perform(*args)
    # Perform Job
  end
end

Different calls

# queue a job
ExampleJob.perform_later(args)
ExampleJob.set(wait_until: Date.tomorrow.noon).perform_later(args)

# Sidekiq job ID
job = ExampleJob.perform_later(args)
jid = job.provider_job_id

Sidekiq API

Reset stats

Sidekiq::Stats.new.reset

Retries queue stats and reset

rs = Sidekiq::RetrySet.new
rs.size
rs.clear

Dead jobs stats and reset

ds = Sidekiq::DeadSet.new
ds.size
ds.clear

Scheduled jobs stats and reset