Module: Skynet::ActiveRecordExtensions
- Defined in:
- lib/skynet/active_record_extensions.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_id, *arguments, &block) ⇒ Object (private)
48 49 50 51 |
# File 'lib/skynet/active_record_extensions.rb', line 48 def method_missing(method_id, *arguments, &block) return super unless method_id.to_s =~ /^(.*)_later$/ send_later($1, *arguments) end |
Instance Method Details
#send_later(method, *arguments) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/skynet/active_record_extensions.rb', line 18 def send_later(method,*arguments) raise NoMethodError.new("Method: #{method} doesn't exist in #{self.class}") unless self.respond_to?(method) data = { :model_class => self.class.to_s, :model_id => self.id, :method => method, } # data[:save] = 1 if save data[:opts] = arguments.to_yaml unless arguments.empty? jobopts = { :single => true, :mappers => 1, :map_data => [data], :name => "send_later #{self.class}##{method}", :map_name => "", :map_timeout => 2.minutes, :reduce_timeout => 2.minutes, :master_timeout => 2.minutes, :master_result_timeout => 2.minutes, :map_reduce_class => Skynet::ActiveRecordAsync, :master_retry => 0, :map_retry => 0 } job = Skynet::AsyncJob.new(jobopts) job.run end |