Module: Workling::Remote

Defined in:
lib/workling/remote.rb,
lib/workling/remote/runners/base.rb,
lib/workling/remote/invokers/base.rb,
lib/workling/remote/runners/spawn_runner.rb,
lib/workling/remote/invokers/basic_poller.rb,
lib/workling/remote/runners/client_runner.rb,
lib/workling/remote/runners/starling_runner.rb,
lib/workling/remote/invokers/threaded_poller.rb,
lib/workling/remote/runners/not_remote_runner.rb,
lib/workling/remote/runners/backgroundjob_runner.rb,
lib/workling/remote/invokers/eventmachine_subscriber.rb

Defined Under Namespace

Modules: Invokers, Runners

Class Method Summary collapse

Class Method Details

.dispatcherObject

retrieve the dispatcher or instantiate it using the defaults



22
23
24
# File 'lib/workling/remote.rb', line 22

def self.dispatcher
  @@dispatcher ||= Workling.default_runner
end

.generate_uid(clazz, method) ⇒ Object

generates a unique identifier for this particular job.



27
28
29
30
# File 'lib/workling/remote.rb', line 27

def self.generate_uid(clazz, method)
  uid = ::Digest::MD5.hexdigest("#{ clazz }:#{ method }:#{ rand(1 << 64) }:#{ Time.now }")
  "#{ clazz.to_s.tableize }/#{ method }/#{ uid }".split("/").join(":")
end

.run(clazz, method, options = {}) ⇒ Object

dispatches to a workling. writes the :uid for this work into the options hash, so make sure you pass in a hash if you want write to a return store in your workling.



34
35
36
37
38
39
40
# File 'lib/workling/remote.rb', line 34

def self.run(clazz, method, options = {})
  uid = Workling::Remote.generate_uid(clazz, method)
  options[:uid] = uid if options.kind_of?(Hash) && !options[:uid]
  Workling.find(clazz, method) # this line raises a WorklingError if the method does not exist. 
  dispatcher.run(clazz, method, options)
  uid
end