Module: MicroQ::DSL
- Defined in:
- lib/micro_q/dsl.rb
Overview
Convenience methods for calling methods asynchronously Adds perform_async by default
Usage class MyWorker
worker :update, :queue => 'non-default'
def update
end
end
MyWorker.update_async is the same as MyWorker.new.async(:queue => ‘non-default’).update
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.attach_async_methods(target, opts) ⇒ Object
For each of the methods given to the Object.worker method define the _async post-fixed version for convenience.
- .define_proxy_method(target, method) ⇒ Object
Class Method Details
.attach_async_methods(target, opts) ⇒ Object
For each of the methods given to the Object.worker method define the _async post-fixed version for convenience
23 24 25 26 27 28 29 |
# File 'lib/micro_q/dsl.rb', line 23 def self.attach_async_methods(target, opts) target.class_eval do (target.[:methods] |= opts.flatten).each do |method| DSL.define_proxy_method target, method end end end |
.define_proxy_method(target, method) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/micro_q/dsl.rb', line 31 def self.define_proxy_method(target, method) target.define_singleton_method(:"#{method}_async") do |*args| MicroQ::Proxy::Instance.new( target..dup.merge(:class => self) ).send(method, *args) end unless respond_to?(:"#{method}_async") end |