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 ⇒ TrueClass, FalseClass
Returns true or false depending if the flow raised any errors or violated any conditions.
-
#concert! ⇒ Array
Returns all steps if successfull.
- #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 ⇒ TrueClass, FalseClass
Returns true or false depending if the flow raised any errors or violated any conditions.
21 22 23 24 25 |
# File 'lib/rockflow/flow.rb', line 21 def concert execute_steps.inject(true) do |result, elem| result && !elem.errors.any? end end |
#concert! ⇒ Array
Returns all steps if successfull. If any error is raised inside the step it is raised.
29 30 31 32 33 34 35 36 |
# File 'lib/rockflow/flow.rb', line 29 def concert! execute_steps @steps.map do |step| step.errors end.flatten.each do |error| raise error end end |
#execute_steps ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rockflow/flow.rb', line 51 def execute_steps while !steps_finished? break if next_free_steps.blank? ::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 step.fail! step.errors << e raise Parallel::Break, e. end end end @steps end |
#next_free_steps ⇒ Object
38 39 40 41 42 |
# File 'lib/rockflow/flow.rb', line 38 def next_free_steps @steps.select do |step| step.after_dependencies_finished? && !step.finished? && !step.failed? 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
44 45 46 47 48 49 |
# File 'lib/rockflow/flow.rb', line 44 def steps_finished? @steps.inject(true) do |result, elem| result = result && (elem.finished? || elem.failed?) result end end |