9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/resque/plugins/async/method.rb', line 9
def async_method(method_name, opts={})
alias_method :"sync_#{method_name}", method_name
return if Rails.env.test?
define_method "#{method_name}" do |*args|
raise NotPersistedError, "Methods can only be async'ed on persisted records (currently: #{inspect})" unless persisted?
my_klass = Resque::Plugins::Async::Worker
my_klass.queue = opts[:queue] ||
send(:class).name.underscore.pluralize
Resque.enqueue(
my_klass,
send(:class).name,
send(:id),
:"sync_#{method_name}",
*args
)
end
end
|