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
commit672f39245744ad3fdaf37afa9b39d7d5327aad7e (patch)
treef59c6f1e16acc8a39fb2e554812b94cacb33a478 /lib
parent31632d46e83914a29a75dab4e0c7a4f36f5ad405 (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
#