Class: Sfn::ExecutionLog

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

Constant Summary collapse

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event) ⇒ ExecutionLog

Returns a new instance of ExecutionLog.



42
43
44
# File 'lib/sfn/execution_log.rb', line 42

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



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

def self.parse(execution_arn)
  profile = {}
  output = nil
  error = 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)
    state_name = parsed_event.state_name

    next if state_name.nil?

    profile[state_name] ||= { input: [], output: [] }
    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
  [output, profile]
end

Instance Method Details

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

Raises:



54
55
56
57
58
59
60
# File 'lib/sfn/execution_log.rb', line 54

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

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

#outputObject



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

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

#profileObject



62
63
64
65
66
67
# File 'lib/sfn/execution_log.rb', line 62

def profile
  {
    input: try_parse(event.dig('stateEnteredEventDetails', 'input')),
    output: try_parse(event.dig('stateExitedEventDetails', 'output'))
  }.compact
end

#state_nameObject



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

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