From 80489e3ffe9b7ba139043cef5b4a7f08a018e4d7 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Fri, 18 Dec 2015 12:52:30 +0200 Subject: 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. --- lib/custodian/queue.rb | 17 +++++++---------- 1 file 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 -- cgit v1.2.1