Module: Workling::Remote

Defined in:
lib/workling/remote.rb

Class Method Summary collapse

Class Method Details

.clientObject



17
18
19
# File 'lib/workling/remote.rb', line 17

def self.client
  @@client ||= Workling.select_and_build_client
end

.generate_uid(clazz, method) ⇒ Object

generates a unique identifier for this particular job.



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

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

.routingObject



11
12
13
# File 'lib/workling/remote.rb', line 11

def self.routing
  @@routing ||= Workling::Routing::ClassAndMethodRouting.new
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.



29
30
31
32
33
34
35
# File 'lib/workling/remote.rb', line 29

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.
  client.dispatch(clazz, method, options)
  uid
end