Sha256: 10920bc13eca39ddda8b3a33008651402e7fb24591c2acc3f1f4d3ec4874ac9a
Contents?: true
Size: 1.32 KB
Versions: 3
Compression:
Stored size: 1.32 KB
Contents
module Pallets class Workflow extend DSL::Workflow attr_reader :context def initialize(context_hash = {}) @id = nil # Passed in context hash needs to be buffered @context = Context.new.merge!(context_hash) end 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, jobs_with_order, serializer.dump_context(context.buffer)) id end def id @id ||= "P#{Pallets::Util.generate_id(self.class.name)}".upcase end private def jobs_with_order self.class.graph.sorted_with_order.map do |task_class, order| job = serializer.dump(construct_job(task_class)) [order, job] end end def construct_job(task_class) {}.tap do |job| job['wfid'] = id job['jid'] = "J#{Pallets::Util.generate_id(task_class)}".upcase job['workflow_class'] = self.class.name job['created_at'] = Time.now.to_f end.merge(self.class.task_config[task_class]) end def backend Pallets.backend end def serializer Pallets.serializer end def self.task_config @task_config ||= {} end def self.graph @graph ||= Graph.new end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
pallets-0.5.1 | lib/pallets/workflow.rb |
pallets-0.5.0 | lib/pallets/workflow.rb |
pallets-0.4.0 | lib/pallets/workflow.rb |