Search code examples
ruby-on-railsredissidekiq

Delete Sidekiq jobs with a particular argument?


Say that at some point I enqueue a job that looks like this:

HardWorker.perform(command_id, user_id)

Is there any way I can remove all the jobs (from the Redis queue) which have a particular command_id associated?


Solution

  • 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