Class: Orchestra::Execution::CollectionStep

Inherits:
Step
  • Object
show all
Defined in:
lib/orchestra/execution.rb

Instance Attribute Summary

Attributes inherited from Step

#context, #name, #node, #operation_execution, #step

Instance Method Summary collapse

Methods inherited from Step

#build_context, execute, #execute, #initialize, #input, new, #to_node

Constructor Details

This class inherits a constructor from Orchestra::Execution::Step

Instance Method Details

#enqueue_job(element, index) ⇒ Object



142
143
144
145
146
147
# File 'lib/orchestra/execution.rb', line 142

def enqueue_job element, index
  operation_execution.thread_pool.enqueue do
    result = context.execute element
    yield [result, index]
  end
end

#enqueue_jobs(batch, &block) ⇒ Object



136
137
138
139
140
# File 'lib/orchestra/execution.rb', line 136

def enqueue_jobs batch, &block
  batch.map.with_index do |element, index|
    enqueue_job element, index, &block
  end
end

#invokeObject



129
130
131
132
133
134
# File 'lib/orchestra/execution.rb', line 129

def invoke
  batch, output = prepare_collection
  jobs = enqueue_jobs batch do |result, index| output[index] = result end
  jobs.each &:wait
  output
end

#prepare_collectionObject



149
150
151
152
153
# File 'lib/orchestra/execution.rb', line 149

def prepare_collection
  batch = context.fetch_collection
  output = [nil] * batch.size
  [batch, output]
end