diff options
author | Steve Kemp <steve@steve.org.uk> | 2012-11-12 22:35:13 +0000 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2012-11-12 22:35:13 +0000 |
commit | d603704eb3d4df5832cadcfe09719b7c2499a2d5 (patch) | |
tree | 5416a4ce55a5ff6b66e2285b1a78dfa3aa2e3b43 | |
parent | 8a6ad7743f98e036b50aeb91a7c81c57e4708f4a (diff) |
Added --flush/-f to flush the queue
-rwxr-xr-x | worker/worker | 26 |
1 files changed, 25 insertions, 1 deletions
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 |