Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: resque/resque
...
head fork: backupify/resque
Checking mergeability… Don't worry, you can still create the pull request.
  • 20 commits
  • 11 files changed
  • 0 commit comments
  • 6 contributors
Commits on May 26, 2010
backupify 832b0f2
Commits on Oct 05, 2010
@nirvdrum nirvdrum Use text/html since it is HTML and this helps with mod_proxy_html. 1fc8a46
Commits on Oct 22, 2010
Dave Benvenuti pulled in newer version of constantize to helper, and changed job to …
…use native implementation, if it exists. this fixes the issue with duplicate module names not being looked up properly
69d6830
Dave Benvenuti Merge branch 'master' of https://github.com/davebenvenuti/resque fc1dc5d
Dave Benvenuti Merge branch 'master' of http://github.com/mogo/resque e302d31
Commits on Nov 03, 2010
Dave Benvenuti made another couple of tweaks to constantize, added a test b569242
Dave Benvenuti Merge branch 'master' of http://github.com/defunkt/resque 92fd97b
Commits on Nov 21, 2010
@wr0ngway wr0ngway ignore rubymine files d1393cf
@wr0ngway wr0ngway Add some simple wildcarding and negation for worker queue names 8975783
@wr0ngway wr0ngway Merge remote branch 'defunkt/master' 0a62442
Commits on Jan 30, 2011
@wr0ngway wr0ngway fix race condition in resque web 485184f
Commits on Feb 14, 2011
@haruska haruska Merge remote branch 'upstream/master' 54a8801
Commits on Mar 25, 2011
@wr0ngway wr0ngway Revert "Add some simple wildcarding and negation for worker queue names"
This reverts commit 8975783.
f70d562
Commits on May 21, 2013
@jzaleski jzaleski Sleep for a random amount of time between 5 and 300 seconds when work…
… cannot be found.
4ea395e
Commits on May 22, 2013
@jzaleski jzaleski Let the work method in "lib/resque/worker.rb" take care of setting th…
…e default sleep-interval
d96d6eb
@jzaleski jzaleski Change "lib/resque/tasks.rb" back to its default implementation 90e6445
@jzaleski jzaleski Add the default value for "interval" back to the "work" method. Also,…
… always generate a random sleep-time between "interval" and 300 seconds
c9f7764
@jzaleski jzaleski Externalize configuration of "{min,max}_interval" -- used by: "work" …
…method, default to: "interval" value
098e6c6
@jzaleski jzaleski Add conversion, validation, and normalization for "interval" 21beb53
@jzaleski jzaleski Merge branch 'staggered_sleep' d11ad26
View
1  .gitignore
@@ -1,2 +1,3 @@
pkg
nbproject
+.idea
View
61 lib/resque/helpers.rb
@@ -40,24 +40,59 @@ def classify(dashed_word)
dashed_word.split('-').each { |part| part[0] = part[0].chr.upcase }.join
end
- # Given a camel cased word, returns the constant it represents
- #
- # constantize('JobName') # => JobName
- def constantize(camel_cased_word)
- camel_cased_word = camel_cased_word.to_s
+ # Ruby 1.9 introduces an inherit argument for Module#const_get and
+ # #const_defined? and changes their default behavior.
+ if Module.method(:const_get).arity == 1
+ # Tries to find a constant with the name specified in the argument string:
+ #
+ # "Module".constantize # => Module
+ # "Test::Unit".constantize # => Test::Unit
+ #
+ # The name is assumed to be the one of a top-level constant, no matter whether
+ # it starts with "::" or not. No lexical context is taken into account:
+ #
+ # C = 'outside'
+ # module M
+ # C = 'inside'
+ # C # => 'inside'
+ # "C".constantize # => 'outside', same as ::C
+ # end
+ #
+ # NameError is raised when the name is not in CamelCase or the constant is
+ # unknown.
+ def constantize(camel_cased_word)
+ camel_cased_word = camel_cased_word.to_s
+
+ if camel_cased_word.include?('-')
+ camel_cased_word = classify(camel_cased_word)
+ end
+
+ names = camel_cased_word.split('::')
+ names.shift if names.empty? || names.first.empty?
- if camel_cased_word.include?('-')
- camel_cased_word = classify(camel_cased_word)
+ constant = Object
+ names.each do |name|
+ constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
+ end
+ constant
end
+ else
+ def constantize(camel_cased_word) #:nodoc:
+ camel_cased_word = camel_cased_word.to_s
+
+ if camel_cased_word.include?('-')
+ camel_cased_word = classify(camel_cased_word)
+ end
- names = camel_cased_word.split('::')
- names.shift if names.empty? || names.first.empty?
+ names = camel_cased_word.split('::')
+ names.shift if names.empty? || names.first.empty?
- constant = Object
- names.each do |name|
- constant = constant.const_get(name) || constant.const_missing(name)
+ constant = Object
+ names.each do |name|
+ constant = constant.const_defined?(name, false) ? constant.const_get(name) : constant.const_missing(name)
+ end
+ constant
end
- constant
end
end
end
View
4 lib/resque/job.rb
@@ -171,7 +171,9 @@ def perform
# Returns the actual class constant represented in this job's payload.
def payload_class
- @payload_class ||= constantize(@payload['class'])
+ @payload_class ||= @payload['class'].respond_to?(:constantize) ?
+ @payload['class'].constantize :
+ constantize(@payload['class'])
end
# Returns an array of args represented in this job's payload.
View
16 lib/resque/server/views/working.erb
@@ -27,8 +27,14 @@
<% else %>
- <% workers = resque.working.reject { |w| w.idle? } %>
- <h1 class='wi'><%= workers.size %> of <%= resque.workers.size %> Workers Working</h1>
+ <%
+ workers = resque.working
+ jobs = workers.collect {|w| w.job }
+ worker_jobs = workers.zip(jobs)
+ worker_jobs = worker_jobs.reject { |w, j| w.idle? }
+ %>
+
+ <h1 class='wi'><%= worker_jobs.size %> of <%= resque.workers.size %> Workers Working</h1>
<p class='intro'>The list below contains all workers which are currently running a job.</p>
<table class='workers'>
<tr>
@@ -37,15 +43,13 @@
<th>Queue</th>
<th>Processing</th>
</tr>
- <% if workers.empty? %>
+ <% if worker_jobs.empty? %>
<tr>
<td colspan="4" class='no-data'>Nothing is happening right now...</td>
</tr>
<% end %>
- <% for worker in workers.sort_by { |w| w.job['run_at'] ? w.job['run_at'] : '' } %>
- <% job = worker.job %>
-
+ <% worker_jobs.sort_by {|w, j| j['run_at'] ? j['run_at'] : '' }.each do |worker, job| %>
<tr>
<td class='icon'><img src="<%=u state = worker.state %>.png" alt="<%= state %>" title="<%= state %>"></td>
<% host, pid, queues = worker.to_s.split(':') %>
View
30 lib/resque/worker.rb
@@ -103,8 +103,7 @@ def validate_queues
# 3. Teardown: This worker is unregistered.
#
# Can be passed an integer representing the polling frequency.
- # The default is 5 seconds, but for a semi-active site you may
- # want to use a smaller value.
+ # For a semi-active site you may want to use a smaller value.
#
# Also accepts a block which will be passed the job as soon as it
# has completed processing. Useful for testing.
@@ -112,6 +111,24 @@ def work(interval = 5, &block)
$0 = "resque: Starting"
startup
+ # We rely heavily on interval below. Ensure that it is a non-negative
+ # integer value
+ interval = [0, interval.to_i].max
+
+ # Ensure that the min_interval is an integer value
+ min_interval = ENV["MIN_INTERVAL"] ? ENV["MIN_INTERVAL"].to_i : interval
+
+ # Ensure that the max_interval is an integer value
+ max_interval = ENV["MAX_INTERVAL"] ? ENV["MAX_INTERVAL"].to_i : interval
+
+ # Increasing and randomizing the polling frequency can help to lessen the
+ # average number of requests/sec that need to be serviced by redis. This
+ # value will only be used when there are no jobs in the queue
+ #
+ # If "min_interval" is erroneously less than "max_interval" the "interval"
+ # value will be used
+ interval = rand(min_interval..max_interval) || interval
+
loop do
break if shutdown?
@@ -133,10 +150,11 @@ def work(interval = 5, &block)
done_working
@child = nil
else
- break if interval.to_i == 0
- log! "Sleeping for #{interval.to_i}"
- procline @paused ? "Paused" : "Waiting for #{@queues.join(',')}"
- sleep interval.to_i
+ break if interval == 0
+ log! "Sleeping for #{interval}"
+ waiting_for = @queues.empty? ? "work" : @queues.join(', ')
+ procline @paused ? "Paused" : "Waiting for #{waiting_for}"
+ sleep interval
end
end
View
2  test/job_hooks_test.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/test_helper'
+require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
context "Resque::Job before_perform" do
include PerformJob
View
2  test/job_plugins_test.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/test_helper'
+require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
context "Multiple plugins with multiple hooks" do
include PerformJob
View
2  test/plugin_test.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/test_helper'
+require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
context "Resque::Plugin finding hooks" do
module SimplePlugin
View
2  test/resque-web_test.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/test_helper'
+require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
require 'resque/server/test_helper'
# Root path test
View
33 test/resque_test.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/test_helper'
+require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
context "Resque" do
setup do
@@ -229,4 +229,35 @@
test "decode bad json" do
assert_nil Resque.decode("{\"error\":\"Module not found \\u002\"}")
end
+
+ test "use objects own constantize implementation if it exists" do
+
+ # make sure classes nested in multiple modules are resolved correctly
+ module SomeModule
+ module SomeOtherModule
+ class SomeClass; end
+ end
+ end
+
+ module SomeOtherModule; end
+
+
+ class Object
+ # for testing, we'll assert that calling constantize on an Object returns
+ # Hash no matter what string its passed, just to ensure the correct method is being
+ # called
+ def constantize
+ return Hash
+ end
+
+ end
+
+ assert_equal Hash, Resque::Job.new(:some_queue, { 'class' => 'SomeClass'} ).payload_class
+
+ # cleanup
+ Object.send :remove_method, :constantize
+
+ # now, assert that we call the helper method's implementation otherwise
+ assert_equal SomeModule::SomeOtherModule::SomeClass, Resque::Job.new(:some_other_queue, { 'class' => 'SomeModule::SomeOtherModule::SomeClass'} ).payload_class
+ end
end
View
6 test/worker_test.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/test_helper'
+require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
context "Resque::Worker" do
setup do
@@ -10,6 +10,10 @@
@worker = Resque::Worker.new(:jobs)
Resque::Job.create(:jobs, SomeJob, 20, '/tmp')
+
+ # ensure that tests run fast by setting the min/max interval values to 0
+ ENV["MIN_INTERVAL"] = "0"
+ ENV["MAX_INTERVAL"] = "0"
end
test "can fail jobs" do

No commit comments for this range

Something went wrong with that request. Please try again.