I've accidentally enqueued a bunch of jobs in Sidekiq. I do not want to wipe my entire Redis store (and reset ALL Sidekiq data and enqueued jobs to nil) but I would like to remove all enqueued jobs that can be identified by a given class. How would I do this?
These answers were helpful, but didn't answer the original question for me. It's possible those solutions are out of date.
You have to access the job's args and grab it's actual job class within the loop scope. I tried the above and it did not work as expected because job.klass
does not return what you'd expect it to.
This is what it returns in the terminal currently:
queue.each do |job|
puts job.klass
end
ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper
=> nil
So my solution was to dig into the job's arguments like so:
queue = Sidekiq::Queue.new("job_queue_name")
queue.each do |job|
puts job.args.first['job_class']
job.delete if job.args.first['job_class'] == "Things::DoesThatThingJob"
end
I'm sure there's a way to write this more elegantly (maybe with a select?) But it's readable. Hope I was able to help others like me that were looking for something like this.