diff --git a/.gitignore b/.gitignore index d87d4be..d36849b 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ spec/reports test/tmp test/version_tmp tmp +*~ diff --git a/README.md b/README.md index de6d6e0..9e3b175 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,8 @@ Resque-round-robin A plugin for Resque that implements round-robin behavior for workers. -resque-dynamic-queues is a pre-requisite, as is Resque 1.19 +resque-dynamic-queues is a pre-requisite, as is Resque 1.19 or higher +(now tested up to 1.21) The standard behavior for Resque workers is to pull a job off a queue, and continue until the queue is empty. Once empty, the worker moves diff --git a/lib/resque/plugins/round_robin/round_robin.rb b/lib/resque/plugins/round_robin/round_robin.rb index f64b210..cfbaa80 100644 --- a/lib/resque/plugins/round_robin/round_robin.rb +++ b/lib/resque/plugins/round_robin/round_robin.rb @@ -26,17 +26,37 @@ def queue_depth queuename DEFAULT_QUEUE_DEPTH = 0 def should_work_on_queue? queuename - return true if @queues.include? '*' # workers with QUEUES=* are special and are not subject to queue depth setting - max = DEFAULT_QUEUE_DEPTH - max = ENV["RESQUE_QUEUE_DEPTH"].to_i if ENV["RESQUE_QUEUE_DEPTH"].present? - return true if max == 0 # 0 means no limiting - cur_depth = queue_depth(queuename) - log! "queue #{queuename} depth = #{cur_depth} max = #{max}" - return true if cur_depth < max - false + + # megahack :( + # + # tried to use an env variable for a less hacky hack, but i dont + # know how to get env variables into the EY resque daemon, and + # Ive been fighting to get this to round-robining system to work + # for five hours now. If you hate this, you can fix it. + # + if Resque.size("python") > 8 +# $stderr.puts "not working on queue, python queue too big. (I have #{queues.size} queues)" + return false + end + + # $stderr.puts "working on queue #{queuename}, python queue is small. (I have #{queues.size} queues)" + + return true if not ['replays-low', 'replays-high'].include?(queuename) + end + + # if any of our queues are wildcarded, then we want to round robin among them + def should_round_robin? +# $stderr.puts "srr, @srr = #{@srr} queues=#{queues} @queues=#{@queues}" + return @srr unless @srr.nil? + @srr = @queues[0].include? '*' end def reserve_with_round_robin + + if not should_round_robin? + return reserve_without_round_robin + end + qs = rotated_queues qs.each do |queue| log! "Checking #{queue}" @@ -44,6 +64,8 @@ def reserve_with_round_robin log! "Found job on #{queue}" return job end + # Start the next search at the queue after the one from which we pick a job. + @n += 1 end nil diff --git a/lib/resque/plugins/round_robin/version.rb b/lib/resque/plugins/round_robin/version.rb index 4a01661..b6d7660 100644 --- a/lib/resque/plugins/round_robin/version.rb +++ b/lib/resque/plugins/round_robin/version.rb @@ -1,7 +1,7 @@ module Resque module Plugins module RoundRobin - VERSION = "0.1.2" + VERSION = "0.1.4" end end end diff --git a/resque-round-robin.gemspec b/resque-round-robin.gemspec index 4b6ee2d..a0eb705 100644 --- a/resque-round-robin.gemspec +++ b/resque-round-robin.gemspec @@ -8,7 +8,7 @@ Gem::Specification.new do |gem| gem.summary = %q{A Resque plugin to modify the worker behavior to pull jobs off queues, round-robin} gem.homepage = "" - gem.add_dependency "resque", "1.19.0" + gem.add_dependency "resque", "~> 1.19" gem.add_dependency "resque-dynamic-queues" gem.add_development_dependency('rspec', '~> 2.5')