diff options
author | Steve Kemp <steve@steve.org.uk> | 2015-12-18 12:52:30 +0200 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2015-12-18 12:52:30 +0200 |
commit | 80489e3ffe9b7ba139043cef5b4a7f08a018e4d7 (patch) | |
tree | 93ed74f464581360e8b200f100bff301ae40d27a /lib | |
parent | ab911df431bed038f1ab791ea06a09dee3209b90 (diff) |
Return values using a reverse-score-range.
This prevents starvation, by ensuring that we pull tests out in
a FIFO fashion - by virtue of the timestamp.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/custodian/queue.rb | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/lib/custodian/queue.rb b/lib/custodian/queue.rb index 8c8ea98..969ba8e 100644 --- a/lib/custodian/queue.rb +++ b/lib/custodian/queue.rb @@ -83,8 +83,12 @@ module Custodian loop do # Get the next job from the queue. - # NOTE: This returns an array. - job = @redis.zrange('custodian_queue', 0, 0) + # + # NOTE: This returns an array - but the array will have only + # one element because we're picking from element 0 with a range + # of 0 - which really means 1,1. + # + job = @redis.ZREVRANGE('custodian_queue', '0', '0') if ! job.empty? @@ -122,14 +126,7 @@ module Custodian # each distinct-test. # # - score = 0 - job_string.split("").each do |x| - score = score + x.ord - end - - # Bound the number to something sane. - score = score & 0xFFFF - + score = Time.now.to_i @redis.zadd('custodian_queue', score, job_string) end |