Skip to content

Commit 7690038

Browse files
author
Jack Veenstra
committed
Fair round-robin scheduling of jobs.
This fixes a bug with picking jobs fairly when there are some empty queues. For example, suppose queues A, and B are empty, while C and D each have 4 jobs. Before this change, the scheduler would start searching at queue A and eventually pick a job from C. Then it would start searching from B and pick another job from C. Then it would start searching at C and pick a job from C. Finally it would start searching from D and pick a job from D. So the jobs would be executed in the order: C, C, C, D, C, D, D, D. But we would like fair scheduling where the jobs alternate between C and D. To fix this bug, the code starts the next search from the next queue that follows the one from which we took the last job. Also bump the version number to 0.1.4.
1 parent 7658284 commit 7690038

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

lib/resque/plugins/round_robin/round_robin.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ def reserve_with_round_robin
4444
log! "Found job on #{queue}"
4545
return job
4646
end
47+
# Start the next search at the queue after the one from which we pick a job.
48+
@n += 1
4749
end
4850

4951
nil
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Resque
22
module Plugins
33
module RoundRobin
4-
VERSION = "0.1.2"
4+
VERSION = "0.1.4"
55
end
66
end
77
end

0 commit comments

Comments
 (0)