Class: Temporal::Workflow::History::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/temporal/workflow/history/event.rb

Constant Summary collapse

EVENT_TYPES =
%w[
  ACTIVITY_TASK_STARTED
  ACTIVITY_TASK_COMPLETED
  ACTIVITY_TASK_FAILED
  ACTIVITY_TASK_TIMED_OUT
  ACTIVITY_TASK_CANCELED
  TIMER_FIRED
  REQUEST_CANCEL_EXTERNAL_WORKFLOW_EXECUTION_FAILED
  SIGNAL_EXTERNAL_WORKFLOW_EXECUTION_FAILED
  EXTERNAL_WORKFLOW_EXECUTION_CANCEL_REQUESTED
  EXTERNAL_WORKFLOW_EXECUTION_SIGNALED
  UPSERT_WORKFLOW_SEARCH_ATTRIBUTES
].freeze
CHILD_WORKFLOW_EVENTS =
%w[
  START_CHILD_WORKFLOW_EXECUTION_FAILED
  CHILD_WORKFLOW_EXECUTION_STARTED
  CHILD_WORKFLOW_EXECUTION_COMPLETED
  CHILD_WORKFLOW_EXECUTION_FAILED
  CHILD_WORKFLOW_EXECUTION_CANCELED
  CHILD_WORKFLOW_EXECUTION_TIMED_OUT
  CHILD_WORKFLOW_EXECUTION_TERMINATED
].freeze
PREFIX =
'EVENT_TYPE_'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_event) ⇒ Event

Returns a new instance of Event.



33
34
35
36
37
38
39
40
# File 'lib/temporal/workflow/history/event.rb', line 33

def initialize(raw_event)
  @id = raw_event.event_id
  @timestamp = raw_event.event_time.to_time
  @type = raw_event.event_type.to_s.gsub(PREFIX, '')
  @attributes = extract_attributes(raw_event)

  freeze
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



31
32
33
# File 'lib/temporal/workflow/history/event.rb', line 31

def attributes
  @attributes
end

#idObject (readonly)

Returns the value of attribute id.



31
32
33
# File 'lib/temporal/workflow/history/event.rb', line 31

def id
  @id
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



31
32
33
# File 'lib/temporal/workflow/history/event.rb', line 31

def timestamp
  @timestamp
end

#typeObject (readonly)

Returns the value of attribute type.



31
32
33
# File 'lib/temporal/workflow/history/event.rb', line 31

def type
  @type
end

Instance Method Details

#originating_event_idObject

Returns the ID of the first event associated with the current event.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/temporal/workflow/history/event.rb', line 43

def originating_event_id
  case type
  when 'TIMER_FIRED'
    attributes.started_event_id
  when 'WORKFLOW_EXECUTION_SIGNALED', 'WORKFLOW_EXECUTION_TERMINATED'
    1 # fixed id for everything related to current workflow
  when *EVENT_TYPES
    attributes.scheduled_event_id
  when *CHILD_WORKFLOW_EVENTS
    attributes.initiated_event_id
  else
    id
  end
end