Class: Mushy::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/mushy/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runner = nil) ⇒ Runner



7
8
9
# File 'lib/mushy/runner.rb', line 7

def initialize runner = nil
  self.runner = runner || self
end

Instance Attribute Details

#runnerObject

Returns the value of attribute runner.



5
6
7
# File 'lib/mushy/runner.rb', line 5

def runner
  @runner
end

Instance Method Details

#build_event(event_data, flow_id, run_id, flux_id) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/mushy/runner.rb', line 44

def build_event event_data, flow_id, run_id, flux_id
  event = Mushy::Event.new
  event.id = SecureRandom.uuid
  event.run_id = run_id
  event.flow_id = flow_id
  event.flux_id = flux_id
  event.data = event_data
  event
end

#find_run(flux, flow) ⇒ Object



37
38
39
40
41
42
# File 'lib/mushy/runner.rb', line 37

def find_run flux, flow
  run = Mushy::Run.new
  run.id = SecureRandom.uuid
  run.flow_id = flow.id
  run
end

#run_event_in_flow(event, flow) ⇒ Object



24
25
26
27
28
# File 'lib/mushy/runner.rb', line 24

def run_event_in_flow event, flow
  flow.fluxs_for(event)
    .map { |s| runner.run_event_with_flux event, s }
    .flatten
end

#run_event_with_flux(event, flux) ⇒ Object



30
31
32
33
34
35
# File 'lib/mushy/runner.rb', line 30

def run_event_with_flux event, flux
  [flux.execute(event.data)]
    .flatten
    .reject { |x| x.nil? }
    .map { |x| x.is_a?(Hash) ? build_event(x, event.flow_id, event.run_id, flux.id) : x }
end

#start(event_data, flux, flow) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/mushy/runner.rb', line 11

def start event_data, flux, flow
  run = find_run flux, flow
  starting_event = build_event event_data, flow.id, run.id, flux.id

  events = run_event_with_flux starting_event, flux

  while events.any?
    events = events.map { |e| runner.run_event_in_flow e, flow }.flatten
  end

  run
end