Class: Orchestra::Execution::Operation

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Observable
Defined in:
lib/orchestra/execution.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conductor, run_list, input, node) ⇒ Operation

Returns a new instance of Operation.



26
27
28
29
30
31
32
33
# File 'lib/orchestra/execution.rb', line 26

def initialize conductor, run_list, input, node
  @conductor = conductor
  @input = input.dup
  @node = node
  @run_list = run_list
  @registry = conductor.build_registry self
  @state = registry.merge input
end

Instance Attribute Details

#conductorObject (readonly)

Returns the value of attribute conductor.



24
25
26
# File 'lib/orchestra/execution.rb', line 24

def conductor
  @conductor
end

#inputObject (readonly)

Returns the value of attribute input.



24
25
26
# File 'lib/orchestra/execution.rb', line 24

def input
  @input
end

#nodeObject (readonly)

Returns the value of attribute node.



24
25
26
# File 'lib/orchestra/execution.rb', line 24

def node
  @node
end

#registryObject (readonly)

Returns the value of attribute registry.



24
25
26
# File 'lib/orchestra/execution.rb', line 24

def registry
  @registry
end

#run_listObject (readonly)

Returns the value of attribute run_list.



24
25
26
# File 'lib/orchestra/execution.rb', line 24

def run_list
  @run_list
end

#stateObject (readonly)

Returns the value of attribute state.



24
25
26
# File 'lib/orchestra/execution.rb', line 24

def state
  @state
end

Instance Method Details

#ensure_inputs_are_present!Object



58
59
60
61
62
# File 'lib/orchestra/execution.rb', line 58

def ensure_inputs_are_present!
  has_dep = state.method :[]
  missing_input = required_dependencies.reject &has_dep
  raise MissingInputError.new missing_input unless missing_input.empty?
end

#executeObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/orchestra/execution.rb', line 35

def execute
  publish :operation_entered, node, node.input if node
  ensure_inputs_are_present!
  run_list.each do |name, step| process name, step end
  publish :operation_exited, node, output if node
  output
rescue => error
  publish :error_raised, error
  raise error
end

#outputObject



46
47
48
# File 'lib/orchestra/execution.rb', line 46

def output
  state.fetch run_list.result
end

#process(name, step) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/orchestra/execution.rb', line 50

def process name, step
  output = Step.execute step, name, self
  state.merge! output
rescue MissingProvisionError => error
  error.name = name.inspect
  raise error
end

#publish(event, *payload) ⇒ Object



64
65
66
67
# File 'lib/orchestra/execution.rb', line 64

def publish event, *payload
  changed
  notify_observers event, *payload
end

#thread_poolObject



69
70
71
# File 'lib/orchestra/execution.rb', line 69

def thread_pool
  conductor.thread_pool
end