forked from tobi/delayed_job
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into jbarnette/master
Conflicts: tasks/jobs.rake
- Loading branch information
Showing
10 changed files
with
334 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
module Delayed | ||
module MessageSending | ||
def send_later(method, *args) | ||
def send_later(method, *args) | ||
Delayed::Job.enqueue Delayed::PerformableMethod.new(self, method.to_sym, args) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,47 @@ | ||
module Delayed | ||
class PerformableMethod < Struct.new(:object, :method, :args) | ||
AR_STRING_FORMAT = /^AR\:([A-Z]\w+)\:(\d+)$/ | ||
|
||
class PerformableMethod < Struct.new(:object, :method, :args) | ||
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) | ||
|
||
self.object = dump(object) | ||
self.args = args.map { |a| dump(a) } | ||
self.method = method.to_sym | ||
end | ||
|
||
def perform | ||
load(object).send(method, *args.map{|a| load(a)}) | ||
rescue ActiveRecord::RecordNotFound | ||
# We cannot do anything about objects which were deleted in the meantime | ||
true | ||
end | ||
true | ||
end | ||
|
||
private | ||
|
||
def load(arg) | ||
case arg | ||
when AR_STRING_FORMAT then $1.constantize.find($2) | ||
when CLASS_STRING_FORMAT then $1.constantize | ||
when AR_STRING_FORMAT then $1.constantize.find($2) | ||
else arg | ||
end | ||
end | ||
|
||
def dump(arg) | ||
case arg | ||
when Class then class_to_string(arg) | ||
when ActiveRecord::Base then ar_to_string(arg) | ||
else arg | ||
end | ||
end | ||
end | ||
|
||
def ar_to_string(obj) | ||
"AR:#{obj.class}:#{obj.id}" | ||
end | ||
end | ||
|
||
def class_to_string(obj) | ||
"CLASS:#{obj.name}" | ||
end | ||
end | ||
end |
Oops, something went wrong.