diff options
Diffstat (limited to 'lib/custodian')
-rw-r--r-- | lib/custodian/queue.rb | 22 |
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 # |