summaryrefslogtreecommitdiff
path: root/worker
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2012-11-12 22:35:13 +0000
committerSteve Kemp <steve@steve.org.uk>2012-11-12 22:35:13 +0000
commitd603704eb3d4df5832cadcfe09719b7c2499a2d5 (patch)
tree5416a4ce55a5ff6b66e2285b1a78dfa3aa2e3b43 /worker
parent8a6ad7743f98e036b50aeb91a7c81c57e4708f4a (diff)
Added --flush/-f to flush the queue
Diffstat (limited to 'worker')
-rwxr-xr-xworker/worker26
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