Skip to content

Pro API

Mike Perham edited this page Mar 30, 2015 · 24 revisions

Sidekiq Pro adds a few API extensions which execute Lua scripts directly in the Redis process for maximum performance. Lua-based features are only available with Redis 2.6+

  • Sidekiq::Queue#delete_job - takes a JID and deletes the corresponding job from the given queue, if it exists. Returns the deleted job or nil.
jid = MyWorker.perform_async
queue = Sidekiq::Queue.new
queue.delete_job(jid)
  • Sidekiq::Queue#delete_by_class - takes a class and deletes all corresponding jobs from the queue. Returns the number of jobs deleted.
MyWorker.perform_async
queue = Sidekiq::Queue.new
queue.delete_by_class(MyWorker)
  • Sidekiq::JobSet#find_job(jid) - this Lua-based version is much faster than the pure Ruby version in Sidekiq.

Job Scanning

Using Sidekiq::RetrySet.new.each { |job| to find a job based on some criteria can be very slow if you have lots of jobs. Sidekiq Pro provides a scan API for job sets: Retry, Scheduled and Dead. Just pass a string that would match any content within the job payload:

Sidekiq::RetrySet.new.scan("NoMethodError") { |job| job.delete }
Sidekiq::DeadSet.new.scan("FTPWorker") { |job| ... }
Sidekiq::ScheduledSet.new.scan(some_jid) { |job| ... }

The scan API requires Redis 2.8+.

Pausing Queues

Sidekiq Pro allows you to pause processing on any queue processed with reliable_fetch via the API:

q = Sidekiq::Queue.new('critical')
q.pause!
q.paused? # => true
q.unpause!

Notes

  1. The Sidekiq process must be using reliable fetch or it will not pause.
  2. It can take up to 10 seconds for pause! and unpause! to take effect.

The Pro API extensions are automatically loaded when you require 'sidekiq-pro' but you can require it directly too:

require 'sidekiq/pro/api'

Clone this wiki locally