diff options
| author | Steve Kemp <steve@steve.org.uk> | 2015-02-18 03:51:35 +0000 | 
|---|---|---|
| committer | Steve Kemp <steve@steve.org.uk> | 2015-02-18 03:51:35 +0000 | 
| commit | 31632d46e83914a29a75dab4e0c7a4f36f5ad405 (patch) | |
| tree | 1eb1e470fad91f58f27437891e798802299c52f6 /lib | |
| parent | ad277813840592e0aed349364403f59d6f6ce7d1 (diff) | |
| parent | d6b84b3b79b4afbec3d6b1394cc95edc0b348436 (diff) | |
Branch-merge.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/custodian/queue.rb | 21 | 
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 | 
