Class: Sfn::ExecutionLog
- Inherits:
-
Object
- Object
- Sfn::ExecutionLog
- Defined in:
- lib/sfn/execution_log.rb
Constant Summary collapse
- EVENTS =
%w[stateEnteredEventDetails stateExitedEventDetails executionSucceededEventDetails executionFailedEventDetails taskScheduledEventDetails].freeze
Instance Attribute Summary collapse
-
#event ⇒ Object
Returns the value of attribute event.
Class Method Summary collapse
Instance Method Summary collapse
- #error(events_json = '{}', dry_run = false) ⇒ Object
-
#initialize(event) ⇒ ExecutionLog
constructor
A new instance of ExecutionLog.
- #output ⇒ Object
- #profile ⇒ Object
- #state_name ⇒ Object
Constructor Details
#initialize(event) ⇒ ExecutionLog
Returns a new instance of ExecutionLog.
48 49 50 |
# File 'lib/sfn/execution_log.rb', line 48 def initialize(event) self.event = event end |
Instance Attribute Details
#event ⇒ Object
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, dry_run = false) ⇒ 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 46 |
# File 'lib/sfn/execution_log.rb', line 20 def self.parse(execution_arn, dry_run = false) profile = {} root_state_name = {} 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, dry_run) 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? root_state_name[parsed_event.event['id']] = state_name end if !root_state_name[parsed_event.event['previousEventId']].nil? && !parsed_event.profile['parameters'].nil? profile[root_state_name[parsed_event.event['previousEventId']]]['parameters'] << parsed_event.profile['parameters'] end end [output, profile] end |
Instance Method Details
#error(events_json = '{}', dry_run = false) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/sfn/execution_log.rb', line 60 def error(events_json = '{}', dry_run = false) return if event['executionFailedEventDetails'].nil? unless dry_run raise ExecutionError.new(event['executionFailedEventDetails']['cause'], event['executionFailedEventDetails']['error'], events_json) end event['executionFailedEventDetails'] end |
#output ⇒ Object
56 57 58 |
# File 'lib/sfn/execution_log.rb', line 56 def output try_parse(event.dig('executionSucceededEventDetails', 'output')) end |
#profile ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/sfn/execution_log.rb', line 72 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_name ⇒ Object
52 53 54 |
# File 'lib/sfn/execution_log.rb', line 52 def state_name event.dig('stateEnteredEventDetails', 'name') || event.dig('stateExitedEventDetails', 'name') end |