summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2015-02-18 03:51:35 +0000
committerSteve Kemp <steve@steve.org.uk>2015-02-18 03:51:35 +0000
commit2fe2e18916da5a0628cb85cc6b5918776b87b159 (patch)
treebeb3e144eee85949a825f1044d662d4d8ab958ed
parentb1b8ec280c5848fd4485a5106a58ea98c37dc905 (diff)
parent81aead2752316c187255d6732dcb14a46b9c4f05 (diff)
Branch-merge.
-rw-r--r--lib/custodian/queue.rb21
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/custodian/queue.rb b/lib/custodian/queue.rb
index 67c5346..9a7d90f 100644
--- a/lib/custodian/queue.rb
+++ b/lib/custodian/queue.rb
@@ -85,13 +85,28 @@ end
#
- # Fetch a job from the queue - the timeout parameter is ignored.
+ # Fetch a job from the queue.
+ #
+ # The timeout is used to specify the period we wait for a new job.
#
def fetch(timeout)
- job = false
- while( ! job )
+ job = nil
+ timeout ||= 0
+
+ #
+ # Don't melt the CPU.
+ #
+ sleep_interval = 0.5
+
+ loop do
job = @redis.lpop( "queue" )
+ break if job or timeout < 0
+
+ sleep( sleep_interval )
+
+ timeout -= sleep_interval
end
+
return( job )
end