Class: Pallets::Workflow

Inherits:
Object
  • Object
show all
Extended by:
DSL::Workflow
Defined in:
lib/pallets/workflow.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DSL::Workflow

task

Constructor Details

#initialize(context_hash = {}) ⇒ Workflow

Returns a new instance of Workflow.



13
14
15
16
17
# 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

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



5
6
7
# File 'lib/pallets/workflow.rb', line 5

def context
  @context
end

Class Method Details

.build(&block) ⇒ Object



7
8
9
10
11
# 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

Instance Method Details

#idObject



27
28
29
# File 'lib/pallets/workflow.rb', line 27

def id
  @id ||= "P#{Pallets::Util.generate_id(self.class.name)}".upcase
end

#runObject

Raises:



19
20
21
22
23
24
25
# 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