diff options
author | Steve Kemp <steve@steve.org.uk> | 2015-02-05 10:28:39 +0000 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2015-02-05 10:28:39 +0000 |
commit | eaa6fd78cc6fd2eacd2d551e7eded0e899458258 (patch) | |
tree | 18c929dc6728a29a6b4166ddab534b83986080fc | |
parent | 328b3b7a7fed9ae69dfa6292c9d49bd89420f349 (diff) |
Simplify the flushing of queues.
Now that we've moved to using redis by default the handling of queue-flushing
needs to change. We can simply get rid of the busy-wait and run a redis
"del" operation.
With that in mind we've moved the flushing logic to our queue abstraction
layer, and simplified our queue-helper script.
-rwxr-xr-x | bin/custodian-queue | 13 | ||||
-rw-r--r-- | lib/custodian/queue.rb | 19 |
2 files changed, 19 insertions, 13 deletions
diff --git a/bin/custodian-queue b/bin/custodian-queue index 01fb381..978cbda 100755 --- a/bin/custodian-queue +++ b/bin/custodian-queue @@ -159,18 +159,7 @@ if __FILE__ == $0 then # Are we flushing the queue? # if ( $FLUSH ) - count = 0 - run = true - while( run ) - begin - job = queue.fetch(1) - exit(0) if ( job.nil? ) - count += 1 - rescue Beanstalk::TimedOut => ex - puts "Flushed #{count} pending jobs." - exit( 0 ) - end - end + queue.flush! end diff --git a/lib/custodian/queue.rb b/lib/custodian/queue.rb index 8d48575..d3513c3 100644 --- a/lib/custodian/queue.rb +++ b/lib/custodian/queue.rb @@ -58,7 +58,13 @@ module Custodian raise "Subclasses must implement this method!" end - end + # + # Empty the queue + # + def flush!() + raise "Subclasses must implement this method!" + end +end @@ -103,6 +109,11 @@ module Custodian def size? @redis.llen( "queue" ) end + + def flush! + @redis.del( "queue" ) + end + end @@ -157,6 +168,12 @@ module Custodian ( stats['current-jobs-ready'] || 0 ) end + def flush! + + while( fetch(1) ) + # nop + end + end end end |