Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
My rake task for clearing Resque queues and stats
# see http://stackoverflow.com/questions/5880962/how-to-destroy-jobs-enqueued-by-resque-workers - old version
# see https://github.com/defunkt/resque/issues/49
# see http://redis.io/commands - new commands
namespace :resque do
desc "Clear pending tasks"
task :clear => :environment do
queues = Resque.queues
queues.each do |queue_name|
puts "Clearing #{queue_name}..."
Resque.redis.del "queue:#{queue_name}"
end
puts "Clearing delayed..." # in case of scheduler - doesn't break if no scheduler module is installed
Resque.redis.keys("delayed:*").each do |key|
Resque.redis.del "#{key}"
end
Resque.redis.del "delayed_queue_schedule"
puts "Clearing stats..."
Resque.redis.set "stat:failed", 0
Resque.redis.set "stat:processed", 0
end
end
@araslanov-e

This comment has been minimized.

Copy link

@araslanov-e araslanov-e commented May 16, 2014

Thanks B)

@beg

This comment has been minimized.

Copy link

@beg beg commented May 19, 2014

Thx !

@robert2d

This comment has been minimized.

Copy link

@robert2d robert2d commented Aug 13, 2014

legend!

@jairovm

This comment has been minimized.

Copy link

@jairovm jairovm commented Sep 3, 2014

I found this useful

puts "Clearing zombie workers..."
Resque.workers.each(&:prune_dead_workers)

Thanks!

@tbbooher

This comment has been minimized.

Copy link

@tbbooher tbbooher commented Jan 3, 2015

much appreciated

@vladCovaliov

This comment has been minimized.

Copy link

@vladCovaliov vladCovaliov commented Mar 31, 2015

This is what works now:

Resque.remove_queue("...")
@chrishough

This comment has been minimized.

Copy link

@chrishough chrishough commented Jan 8, 2017

Updated to merge all of the above and adjust for rubocop:

  # see http://stackoverflow.com/questions/5880962/how-to-destroy-jobs-enqueued-by-resque-workers - old version
  # see https://github.com/defunkt/resque/issues/49
  # see http://redis.io/commands - new commands
  desc 'Clear pending tasks'
  task clear: :environment do
    queues = Resque.queues
    queues.each do |queue_name|
      puts "Clearing #{queue_name}..."
      Resque.remove_queue("queue:#{queue_name}")
    end

    puts 'Clearing delayed...'
    Resque.redis.keys('delayed:*').each do |key|
      Resque.redis.del key.to_s
    end
    Resque.redis.del 'delayed_queue_schedule'

    puts 'Clearing stats...'
    Resque.redis.set 'stat:failed', 0
    Resque.redis.set 'stat:processed', 0

    puts 'Clearing zombie workers...'
    Resque.workers.each(&:prune_dead_workers)
  end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.