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



55
56
57
58
59
60
# File 'lib/zenaton/engine.rb', line 55

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



46
47
48
49
50
# File 'lib/zenaton/engine.rb', line 46

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

#schedule(jobs, cron) ⇒ Array<String>?

Executes scheduling jobs synchronously

Parameters:

Returns:

  • (Array<String>, nil)

    the results if executed locally, or nil



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/zenaton/engine.rb', line 31

def schedule(jobs, cron)
  jobs.map(&method(:check_argument))
  jobs.map do |job|
    if job.is_a? Interfaces::Workflow
      @client.start_scheduled_workflow(job, cron)
    else
      @client.start_scheduled_task(job, cron)
    end
  end
  nil
end