From d603704eb3d4df5832cadcfe09719b7c2499a2d5 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Mon, 12 Nov 2012 22:35:13 +0000 Subject: Added --flush/-f to flush the queue --- worker/worker | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'worker') diff --git a/worker/worker b/worker/worker index 2eb425e..95fb81d 100755 --- a/worker/worker +++ b/worker/worker @@ -86,6 +86,21 @@ class Custodian end + # + # Flush the queue. + # + def flush_queue! + while( true ) + begin + job = @queue.reserve(1) + id = job.id + puts "\tDeleted job #{id}" if ( ENV['VERBOSE'] ) + job.delete + rescue Beanstalk::TimedOut => ex + return + end + end + end # # Process jobs from the queue - never return. @@ -189,12 +204,15 @@ if __FILE__ == $0 then begin opts = GetoptLong.new( - [ "--verbose", "-v", GetoptLong::NO_ARGUMENT ] + [ "--verbose", "-v", GetoptLong::NO_ARGUMENT ], + [ "--flush", "-f", GetoptLong::NO_ARGUMENT ] ) opts.each do |opt, arg| case opt when "--verbose": ENV["VERBOSE"] = "1" + when "--flush": + ENV["FLUSH"] = "1" end end rescue StandardError => ex @@ -203,5 +221,11 @@ if __FILE__ == $0 then end worker = Custodian.new() + + if ( ENV['FLUSH'] ) + worker.flush_queue! + exit(0) + end + worker.run! end -- cgit v1.2.1