Class: Sfn::ExecutionLog

Inherits:
Object
  • Object
show all
Defined in:
lib/sfn/execution_log.rb

Constant Summary collapse

EVENTS =
%w[stateEnteredEventDetails stateExitedEventDetails executionSucceededEventDetails
executionFailedEventDetails taskScheduledEventDetails].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event) ⇒ ExecutionLog

Returns a new instance of ExecutionLog.



47
48
49
# File 'lib/sfn/execution_log.rb', line 47

def initialize(event)
  self.event = event
end

Instance Attribute Details

#eventObject

Returns the value of attribute event.



15
16
17
# File 'lib/sfn/execution_log.rb', line 15

def event
  @event
end

Class Method Details

.parse(execution_arn) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sfn/execution_log.rb', line 20

def self.parse(execution_arn)
  profile = {}
  output = nil
  error = nil
  state_name = nil
  events_json = AwsCli.run('stepfunctions', 'get-execution-history',
                           { 'execution-arn': execution_arn.to_s, query: "'events[?#{EVENTS.join(' || ')}]'" })
  JSON.parse(events_json).each do |event|
    parsed_event = new(event)

    output ||= parsed_event.output
    error  ||= parsed_event.error(events_json)
    last_state_name = state_name
    state_name = parsed_event.state_name

    unless state_name.nil?
      profile[state_name] ||= { 'input' => [], 'output' => [], 'parameters' => [] }
      profile[state_name]['input'] << parsed_event.profile['input'] unless parsed_event.profile['input'].nil?
      profile[state_name]['output'] << parsed_event.profile['output'] unless parsed_event.profile['output'].nil?
    end
    if !last_state_name.nil? && !parsed_event.profile['parameters'].nil?
      profile[last_state_name]['parameters'] << parsed_event.profile['parameters']
    end
  end
  [output, profile]
end

Instance Method Details

#error(events_json = '{}') ⇒ Object

Raises:



59
60
61
62
63
64
65
# File 'lib/sfn/execution_log.rb', line 59

def error(events_json = '{}')
  return if event['executionFailedEventDetails'].nil?

  raise ExecutionError.new(event['executionFailedEventDetails']['cause'],
                           event['executionFailedEventDetails']['error'],
                           events_json)
end

#outputObject



55
56
57
# File 'lib/sfn/execution_log.rb', line 55

def output
  try_parse(event.dig('executionSucceededEventDetails', 'output'))
end

#profileObject



67
68
69
70
71
72
73
# File 'lib/sfn/execution_log.rb', line 67

def profile
  {
    'input' => try_parse(event.dig('stateEnteredEventDetails', 'input')),
    'output' => try_parse(event.dig('stateExitedEventDetails', 'output')),
    'parameters' => try_parse(event.dig('taskScheduledEventDetails', 'parameters'))
  }.compact
end

#state_nameObject



51
52
53
# File 'lib/sfn/execution_log.rb', line 51

def state_name
  event.dig('stateEnteredEventDetails', 'name') || event.dig('stateExitedEventDetails', 'name')
end