Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed a bug that prevented jobs in sub modules from being serialized …

…correctly
  • Loading branch information...
commit 4fd41a9595dc193d82032e4de2b5ba9a8637cbc1 1 parent d0a9c2d
@tobi tobi authored
Showing with 35 additions and 5 deletions.
  1. +8 −4 lib/delayed/performable_method.rb
  2. +27 −1 spec/job_spec.rb
View
12 lib/delayed/performable_method.rb
@@ -1,7 +1,7 @@
module Delayed
class PerformableMethod < Struct.new(:object, :method, :args)
- CLASS_STRING_FORMAT = /^CLASS\:([A-Z]\w+)$/
- AR_STRING_FORMAT = /^AR\:([A-Z]\w+)\:(\d+)$/
+ CLASS_STRING_FORMAT = /^CLASS\:([A-Z][\w\:]+)$/
+ AR_STRING_FORMAT = /^AR\:([A-Z][\w\:]+)\:(\d+)$/
def initialize(object, method, args)
raise NoMethodError, "undefined method `#{method}' for #{self.inspect}" unless object.respond_to?(method)
@@ -11,8 +11,12 @@ def initialize(object, method, args)
self.method = method.to_sym
end
- def display_name
- "#{object}##{method}"
+ def display_name
+ case self.object
+ when CLASS_STRING_FORMAT then "#{$1}.#{method}"
+ when AR_STRING_FORMAT then "#{$1}##{method}"
+ else "Unknown##{method}"
+ end
end
def perform
View
28 spec/job_spec.rb
@@ -8,6 +8,14 @@ def perform; @@runs += 1; end
class ErrorJob
cattr_accessor :runs; self.runs = 0
def perform; raise 'did not work'; end
+end
+
+module M
+ class ModuleJob
+ cattr_accessor :runs; self.runs = 0
+ def perform; @@runs += 1; end
+ end
+
end
describe Delayed::Job do
@@ -61,7 +69,17 @@ def perform; raise 'did not work'; end
SimpleJob.runs.should == 1
end
+
+
+ it "should work with jobs in modules" do
+ M::ModuleJob.runs.should == 0
+
+ Delayed::Job.enqueue M::ModuleJob.new
+ Delayed::Job.work_off
+ M::ModuleJob.runs.should == 1
+ end
+
it "should re-schedule by about 1 second at first and increment this more and more minutes when it fails to execute properly" do
Delayed::Job.enqueue ErrorJob.new
Delayed::Job.work_off(1)
@@ -196,7 +214,15 @@ def perform; raise 'did not work'; end
it "should be the method that will be called if its a performable method object" do
Delayed::Job.send_later(:clear_locks!)
- Delayed::Job.last.name.should == 'CLASS:Delayed::Job#clear_locks!'
+ Delayed::Job.last.name.should == 'Delayed::Job.clear_locks!'
+
+ end
+ it "should be the instance method that will be called if its a performable method object" do
+ story = Story.create :text => "..."
+
+ story.send_later(:save)
+
+ Delayed::Job.last.name.should == 'Story#save'
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.