Class: Workling::Clients::SpawnClient

Inherits:
Base
  • Object
show all
Includes:
Spawn
Defined in:
lib/workling/clients/spawn_client.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#close, #connect, load, #logger, #request, #retrieve, #subscribe

Class Method Details

.installed?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
# File 'lib/workling/clients/spawn_client.rb', line 19

def self.installed?
  begin
    require 'spawn'
  rescue LoadError
  end

  Object.const_defined? "Spawn"
end

.optionsObject



29
30
31
32
# File 'lib/workling/clients/spawn_client.rb', line 29

def self.options
  # use thread for development and test modes. easier to hunt down exceptions that way.
  @@options ||= { :method => (RAILS_ENV == "test" || RAILS_ENV == "development" ? :fork : :thread) }
end

Instance Method Details

#dispatch(clazz, method, options = {}) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/workling/clients/spawn_client.rb', line 36

def dispatch(clazz, method, options = {})
  spawn(SpawnClient.options) do # exceptions are trapped in here. 
    Workling.find(clazz, method).dispatch_to_worker_method(method, options)
  end

  return nil # that means nothing!
end