Module: Skynet::ObjectExtensions

Defined in:
lib/skynet/object_extensions.rb

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)



42
43
44
45
# File 'lib/skynet/object_extensions.rb', line 42

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, &block) ⇒ Object



3
4
5
6
7
8
9
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
35
36
37
38
# File 'lib/skynet/object_extensions.rb', line 3

def send_later(method, *arguments, &block)
  
  raise ArgumentError("send_later can not serialize blocks.") if block_given?

  if is_a?(Class) or is_a?(Module)
    data = {
      :class_name => name,
      :method     => method,
      :arguments  => arguments
    }.to_yaml
  else
    data = {
      :object    => self,
      :method    => method,
      :arguments => arguments
    }.to_yaml
  end

  jobopts = {
    :single                => true,
    :mappers               => 1,
    :map_data              => [data],
    :name                  => "send_later #{data[:class_name] ? "#{self}.#{method}" : "#{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::ObjectAsync,
    :master_retry          => 0,
    :map_retry             => 0
  }   
  job = Skynet::AsyncJob.new(jobopts)
  job.run

end