class Pallets::Workflow
Attributes
context[R]
Public Class Methods
build(&block)
click to toggle source
# File lib/pallets/workflow.rb, line 7 def self.build(&block) Class.new(self).tap do |workflow_class| workflow_class.instance_eval(&block) end end
new(context_hash = {})
click to toggle source
# File lib/pallets/workflow.rb, line 13 def initialize(context_hash = {}) @id = nil # Passed in context hash needs to be buffered @context = Context.new.merge!(context_hash) end
Private Class Methods
graph()
click to toggle source
# File lib/pallets/workflow.rb, line 74 def self.graph @graph ||= Graph.new end
name()
click to toggle source
Calls superclass method
# File lib/pallets/workflow.rb, line 66 def self.name @name ||= super || '<Anonymous>' end
task_config()
click to toggle source
# File lib/pallets/workflow.rb, line 70 def self.task_config @task_config ||= {} end
Public Instance Methods
id()
click to toggle source
# File lib/pallets/workflow.rb, line 27 def id @id ||= "P#{Pallets::Util.generate_id(self.class.name)}".upcase end
run()
click to toggle source
# File lib/pallets/workflow.rb, line 19 def run raise WorkflowError, "#{self.class.name} has no tasks. Workflows "\ "must contain at least one task" if self.class.graph.empty? backend.run_workflow(id, *prepare_jobs, serializer.dump_context(context.buffer)) id end
Private Instance Methods
backend()
click to toggle source
# File lib/pallets/workflow.rb, line 58 def backend Pallets.backend end
construct_job(task_alias)
click to toggle source
# File lib/pallets/workflow.rb, line 50 def construct_job(task_alias) Hash[self.class.task_config[task_alias]].tap do |job| job['wfid'] = id job['jid'] = "J#{Pallets::Util.generate_id(job['task_class'])}".upcase job['created_at'] = Time.now.to_f end end
prepare_jobs()
click to toggle source
# File lib/pallets/workflow.rb, line 33 def prepare_jobs jobs = [] jobmasks = Hash.new { |h, k| h[k] = [] } acc = {} self.class.graph.each do |task_alias, dependencies| job_hash = construct_job(task_alias) acc[task_alias] = job_hash['jid'] job = serializer.dump(job_hash) jobs << [dependencies.size, job] dependencies.each { |d| jobmasks[acc[d]] << [-1, job] } end [jobs, jobmasks] end
serializer()
click to toggle source
# File lib/pallets/workflow.rb, line 62 def serializer Pallets.serializer end