使用特定参数删除Sidekiq作业?

时间:2014-07-17 20:27:15

标签: ruby-on-rails redis sidekiq

说在某些时候我将一个看起来像这样的工作排队:

HardWorker.perform(command_id, user_id)

有什么方法可以删除所有与command_id关联的作业(来自Redis队列)?

1 个答案:

答案 0 :(得分:1)

command_id = 'command id to delete'

queue = Sidekiq::Queue.new('the_queue_name')

queue.each do |job|
  if job.klass == 'HardWorker' && job.args.first == command_id
    job.delete
  end
end