10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/resque/plugins/async/method.rb', line 10
def async_method method_name, options = {}
puts "options => #{options}"
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 self.persisted?
my_klass = Resque::Plugins::Async::Worker
my_klass.queue = options[:queue] || __send__(:class).name.underscore.pluralize.to_sym
my_klass.loner = options[:loner] || false
my_klass.lock_timeout = options[:lock_timeout] || 0
my_klass.loner = true if my_klass.lock_timeout > 0
Resque.enqueue(
my_klass,
__send__(:class).name,
__send__(:id),
"sync_#{method_name}".to_sym,
*args
)
end
end
|