lib/pallets/workflow.rb in pallets-0.5.1 vs lib/pallets/workflow.rb in pallets-0.6.0

- old
+ new

@@ -2,10 +2,16 @@ class Workflow extend DSL::Workflow attr_reader :context + def self.build(&block) + Class.new(self).tap do |workflow_class| + workflow_class.instance_eval(&block) + end + end + def initialize(context_hash = {}) @id = nil # Passed in context hash needs to be buffered @context = Context.new.merge!(context_hash) end @@ -23,30 +29,33 @@ end private def jobs_with_order - self.class.graph.sorted_with_order.map do |task_class, order| - job = serializer.dump(construct_job(task_class)) + self.class.graph.sorted_with_order.map do |task_alias, order| + job = serializer.dump(construct_job(task_alias)) [order, job] end end - def construct_job(task_class) - {}.tap do |job| + 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(task_class)}".upcase - job['workflow_class'] = self.class.name + job['jid'] = "J#{Pallets::Util.generate_id(job['task_class'])}".upcase job['created_at'] = Time.now.to_f - end.merge(self.class.task_config[task_class]) + end end def backend Pallets.backend end def serializer Pallets.serializer + end + + def self.name + @name ||= super || '<Anonymous>' end def self.task_config @task_config ||= {} end