summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2015-02-18 04:10:36 +0000
committerSteve Kemp <steve@steve.org.uk>2015-02-18 04:10:36 +0000
commit8312615574ab9b0d72b94bf6fe9dba13eabc0b6f (patch)
tree0e306729ef8e1eb2c550856b2eb20d3143825a87 /lib
parent2fe2e18916da5a0628cb85cc6b5918776b87b159 (diff)
Updated the way we wait for jobs.
The new approach uses the redis gems timeout functionality and ensures we never return a null-job. Instead we timeout and repeat with a stalling-sleep in the way. This closes #9553.
Diffstat (limited to 'lib')
-rw-r--r--lib/custodian/queue.rb22
1 files changed, 7 insertions, 15 deletions
diff --git a/lib/custodian/queue.rb b/lib/custodian/queue.rb
index 9a7d90f..c48bba3 100644
--- a/lib/custodian/queue.rb
+++ b/lib/custodian/queue.rb
@@ -87,27 +87,19 @@ end
#
# Fetch a job from the queue.
#
- # The timeout is used to specify the period we wait for a new job.
+ # The timeout is used to specify the period we wait for a new job, and
+ # we pause that same period between fetches.
#
- def fetch(timeout)
+ def fetch(timeout = 1)
job = nil
- timeout ||= 0
- #
- # Don't melt the CPU.
- #
- sleep_interval = 0.5
+ while( 1 )
- loop do
- job = @redis.lpop( "queue" )
- break if job or timeout < 0
+ foo, job = @redis.blpop( "queue", :timeout => timeout )
+ return job if ( job )
- sleep( sleep_interval )
-
- timeout -= sleep_interval
+ sleep( timeout )
end
-
- return( job )
end
#