Class: Zenaton::Engine

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/zenaton/engine.rb

Overview

Zenaton Engine is a singleton class that stores a reference to the current client and processor. It then handles job processing either locally or through the processor with Zenaton workers To access the instance, call ‘Zenaton::Engine.instance`

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#processor=(value) ⇒ Object (writeonly)

Parameters:



19
20
21
# File 'lib/zenaton/engine.rb', line 19

def processor=(value)
  @processor = value
end

Instance Method Details

#dispatch(jobs) ⇒ Object

Executes jobs asynchronously

Parameters:

Returns:

  • nil



39
40
41
42
43
44
# File 'lib/zenaton/engine.rb', line 39

def dispatch(jobs)
  jobs.map(&method(:check_argument))
  jobs.map(&method(:local_dispatch)) if process_locally?(jobs)
  @processor&.process(jobs, false) unless jobs.length.zero?
  nil
end

#execute(jobs) ⇒ Array<String>?

Executes jobs synchronously

Parameters:

Returns:

  • (Array<String>, nil)

    the results if executed locally, or nil



30
31
32
33
34
# File 'lib/zenaton/engine.rb', line 30

def execute(jobs)
  jobs.map(&method(:check_argument))
  return jobs.map(&:handle) if process_locally?(jobs)
  @processor.process(jobs, true)
end