class Zenaton::Engine
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`
Attributes
processor[W]
@param value [Zenaton::Processor]
Public Class Methods
new()
click to toggle source
@private
# File lib/zenaton/engine.rb, line 22 def initialize @client = Zenaton::Client.instance @processor = nil end
Public Instance Methods
dispatch(jobs)
click to toggle source
Executes jobs asynchronously @param jobs [Array<Zenaton::Interfaces::Job>] @return nil
# 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)
click to toggle source
Executes jobs synchronously @param jobs [Array<Zenaton::Interfaces::Job>] @return [Array<String>, nil] the results if executed locally, or nil
# 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)
click to toggle source
Executes scheduling jobs synchronously @param jobs [Array<Zenaton::Interfaces::Job>] @param cron String @return [Array<String>, nil] the results if executed locally, or nil
# 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
Private Instance Methods
check_argument(job)
click to toggle source
# File lib/zenaton/engine.rb, line 76 def check_argument(job) raise InvalidArgumentError, error_message unless valid_job?(job) end
error_message()
click to toggle source
# File lib/zenaton/engine.rb, line 80 def error_message 'You can only execute or dispatch Zenaton Task or Worflow' end
local_dispatch(job)
click to toggle source
# File lib/zenaton/engine.rb, line 68 def local_dispatch(job) if job.is_a? Interfaces::Workflow @client.start_workflow(job) else @client.start_task(job) end end
process_locally?(jobs)
click to toggle source
# File lib/zenaton/engine.rb, line 64 def process_locally?(jobs) jobs.length.zero? || @processor.nil? end
valid_job?(job)
click to toggle source
# File lib/zenaton/engine.rb, line 84 def valid_job?(job) job.is_a?(Interfaces::Task) || job.is_a?(Interfaces::Workflow) end