Skip to content

Commit 4fd41a9

Browse files
author
Tobias Lütke
committed
Fixed a bug that prevented jobs in sub modules from being serialized correctly
1 parent d0a9c2d commit 4fd41a9

2 files changed

Lines changed: 35 additions & 5 deletions

File tree

lib/delayed/performable_method.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Delayed
22
class PerformableMethod < Struct.new(:object, :method, :args)
3-
CLASS_STRING_FORMAT = /^CLASS\:([A-Z]\w+)$/
4-
AR_STRING_FORMAT = /^AR\:([A-Z]\w+)\:(\d+)$/
3+
CLASS_STRING_FORMAT = /^CLASS\:([A-Z][\w\:]+)$/
4+
AR_STRING_FORMAT = /^AR\:([A-Z][\w\:]+)\:(\d+)$/
55

66
def initialize(object, method, args)
77
raise NoMethodError, "undefined method `#{method}' for #{self.inspect}" unless object.respond_to?(method)
@@ -11,8 +11,12 @@ def initialize(object, method, args)
1111
self.method = method.to_sym
1212
end
1313

14-
def display_name
15-
"#{object}##{method}"
14+
def display_name
15+
case self.object
16+
when CLASS_STRING_FORMAT then "#{$1}.#{method}"
17+
when AR_STRING_FORMAT then "#{$1}##{method}"
18+
else "Unknown##{method}"
19+
end
1620
end
1721

1822
def perform

spec/job_spec.rb

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ def perform; @@runs += 1; end
88
class ErrorJob
99
cattr_accessor :runs; self.runs = 0
1010
def perform; raise 'did not work'; end
11+
end
12+
13+
module M
14+
class ModuleJob
15+
cattr_accessor :runs; self.runs = 0
16+
def perform; @@runs += 1; end
17+
end
18+
1119
end
1220

1321
describe Delayed::Job do
@@ -61,7 +69,17 @@ def perform; raise 'did not work'; end
6169

6270
SimpleJob.runs.should == 1
6371
end
72+
73+
74+
it "should work with jobs in modules" do
75+
M::ModuleJob.runs.should == 0
76+
77+
Delayed::Job.enqueue M::ModuleJob.new
78+
Delayed::Job.work_off
6479

80+
M::ModuleJob.runs.should == 1
81+
end
82+
6583
it "should re-schedule by about 1 second at first and increment this more and more minutes when it fails to execute properly" do
6684
Delayed::Job.enqueue ErrorJob.new
6785
Delayed::Job.work_off(1)
@@ -196,7 +214,15 @@ def perform; raise 'did not work'; end
196214

197215
it "should be the method that will be called if its a performable method object" do
198216
Delayed::Job.send_later(:clear_locks!)
199-
Delayed::Job.last.name.should == 'CLASS:Delayed::Job#clear_locks!'
217+
Delayed::Job.last.name.should == 'Delayed::Job.clear_locks!'
218+
219+
end
220+
it "should be the instance method that will be called if its a performable method object" do
221+
story = Story.create :text => "..."
222+
223+
story.send_later(:save)
224+
225+
Delayed::Job.last.name.should == 'Story#save'
200226
end
201227
end
202228

0 commit comments

Comments
 (0)