Class: Rockflow::Flow

Inherits:
Object
  • Object
show all
Defined in:
lib/rockflow/flow.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#payloadObject

Returns the value of attribute payload.



4
5
6
# File 'lib/rockflow/flow.rb', line 4

def payload
  @payload
end

#stepsObject

Returns the value of attribute steps.



4
5
6
# File 'lib/rockflow/flow.rb', line 4

def steps
  @steps
end

Instance Method Details

#concertObject



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_stepsObject



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.message
      end
    end
  end
  @steps
end

#next_free_stepsObject



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

#setupObject



12
13
# File 'lib/rockflow/flow.rb', line 12

def setup
end

#steps_finished?Boolean

Returns:

  • (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