Skip to content

Instantly share code, notes, and snippets.

@austra
Last active July 21, 2019 21:51
Show Gist options
  • Save austra/e7324a8057da26cf0384b5808f8654ca to your computer and use it in GitHub Desktop.
Save austra/e7324a8057da26cf0384b5808f8654ca to your computer and use it in GitHub Desktop.
delete jobs from resque by class
With Resque:
queue_name = 'default'
jobs = Resque.data_store.peek_in_queue(queue_name, 0, 500_000); nil;
deleted_count = 0
jobs.each do |job|
decoded_job = Resque.decode(job)
if decoded_job['class'] == "My::Class::Name"
Resque.data_store.remove_from_queue(queue_name, job)
deleted_count += 1
end
end
puts deleted_count
With Redis:
total_jobs = Resque.redis.llen('queue:default')
total_jobs.times do |i|
job = Resque.redis.lindex('queue:default', i)
h = Resque.decode(job)
forward_job = h["class"] == "My::Class::Name"
if forward_job
Resque.redis.lrem('queue:default', 0, job)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment