Class: Rockflow::Flow
- Inherits:
-
Object
- Object
- Rockflow::Flow
- Defined in:
- lib/rockflow/flow.rb
Instance Attribute Summary collapse
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#steps ⇒ Object
Returns the value of attribute steps.
Instance Method Summary collapse
- #concert ⇒ Object
- #concert! ⇒ Object
- #execute_steps ⇒ Object
-
#initialize(payload = {}) ⇒ Flow
constructor
A new instance of Flow.
- #next_free_steps ⇒ Object
- #rock(klazz, opts = {}) ⇒ Object
- #setup ⇒ Object
- #steps_finished? ⇒ Boolean
Constructor Details
#initialize(payload = {}) ⇒ Flow
Returns a new instance of Flow.
6 7 8 9 10 |
# File 'lib/rockflow/flow.rb', line 6 def initialize(payload = {}) @steps = [] @payload = payload setup end |
Instance Attribute Details
#payload ⇒ Object
Returns the value of attribute payload.
4 5 6 |
# File 'lib/rockflow/flow.rb', line 4 def payload @payload end |
#steps ⇒ Object
Returns the value of attribute steps.
4 5 6 |
# File 'lib/rockflow/flow.rb', line 4 def steps @steps end |
Instance Method Details
#concert ⇒ Object
19 20 21 22 23 |
# File 'lib/rockflow/flow.rb', line 19 def concert execute_steps.inject(true) do |result, elem| result && !elem.errors.any? end end |
#concert! ⇒ Object
25 26 27 |
# File 'lib/rockflow/flow.rb', line 25 def concert! execute_steps end |
#execute_steps ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rockflow/flow.rb', line 42 def execute_steps while !steps_finished? ::Parallel.each(next_free_steps, threads_or_processes.to_sym => Rockflow.configuration.thread_or_processes) do |step| begin step.execute_pre_conditions step.it_up unless step.failed? step.execute_post_conditions step.finish! unless step.failed? rescue e raise Parallel::Break, e. end end end @steps end |
#next_free_steps ⇒ Object
29 30 31 32 33 |
# File 'lib/rockflow/flow.rb', line 29 def next_free_steps @steps.select do |step| step.after_dependencies_finished? && !step.finished? end end |
#rock(klazz, opts = {}) ⇒ Object
15 16 17 |
# File 'lib/rockflow/flow.rb', line 15 def rock(klazz, opts = {}) @steps << klazz.new(self, opts) end |
#setup ⇒ Object
12 13 |
# File 'lib/rockflow/flow.rb', line 12 def setup end |
#steps_finished? ⇒ Boolean
35 36 37 38 39 40 |
# File 'lib/rockflow/flow.rb', line 35 def steps_finished? @steps.inject(true) do |result, elem| result = result && (elem.finished? || elem.failed?) result end end |