Class: Temporal::Workflow::History::EventTarget

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

Defined Under Namespace

Classes: UnexpectedEventType

Constant Summary collapse

ACTIVITY_TYPE =
:activity
CANCEL_ACTIVITY_REQUEST_TYPE =
:cancel_activity_request
TIMER_TYPE =
:timer
CANCEL_TIMER_REQUEST_TYPE =
:cancel_timer_request
CHILD_WORKFLOW_TYPE =
:child_workflow
MARKER_TYPE =
:marker
EXTERNAL_WORKFLOW_TYPE =
:external_workflow
CANCEL_EXTERNAL_WORKFLOW_REQUEST_TYPE =
:cancel_external_workflow_request
WORKFLOW_TYPE =
:workflow
CANCEL_WORKFLOW_REQUEST_TYPE =
:cancel_workflow_request
TARGET_TYPES =
{
  'ACTIVITY_TASK'                              => ACTIVITY_TYPE,
  'ACTIVITY_TASK_CANCEL'                       => CANCEL_ACTIVITY_REQUEST_TYPE,
  'REQUEST_CANCEL_ACTIVITY_TASK'               => CANCEL_ACTIVITY_REQUEST_TYPE,
  'TIMER'                                      => TIMER_TYPE,
  'CANCEL_TIMER'                               => CANCEL_TIMER_REQUEST_TYPE,
  'CHILD_WORKFLOW_EXECUTION'                   => CHILD_WORKFLOW_TYPE,
  'START_CHILD_WORKFLOW_EXECUTION'             => CHILD_WORKFLOW_TYPE,
  'MARKER'                                     => MARKER_TYPE,
  'EXTERNAL_WORKFLOW_EXECUTION'                => EXTERNAL_WORKFLOW_TYPE,
  'SIGNAL_EXTERNAL_WORKFLOW_EXECUTION'         => EXTERNAL_WORKFLOW_TYPE,
  'EXTERNAL_WORKFLOW_EXECUTION_CANCEL'         => CANCEL_EXTERNAL_WORKFLOW_REQUEST_TYPE,
  'REQUEST_CANCEL_EXTERNAL_WORKFLOW_EXECUTION' => CANCEL_EXTERNAL_WORKFLOW_REQUEST_TYPE,
  'UPSERT_WORKFLOW_SEARCH_ATTRIBUTES'          => WORKFLOW_TYPE,
  'WORKFLOW_EXECUTION'                         => WORKFLOW_TYPE,
  'WORKFLOW_EXECUTION_CANCEL'                  => CANCEL_WORKFLOW_REQUEST_TYPE,
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, type) ⇒ EventTarget

Returns a new instance of EventTarget.



54
55
56
57
58
59
# File 'lib/temporal/workflow/history/event_target.rb', line 54

def initialize(id, type)
  @id = id
  @type = type

  freeze
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



38
39
40
# File 'lib/temporal/workflow/history/event_target.rb', line 38

def id
  @id
end

#typeObject (readonly)

Returns the value of attribute type.



38
39
40
# File 'lib/temporal/workflow/history/event_target.rb', line 38

def type
  @type
end

Class Method Details

.from_event(event) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/temporal/workflow/history/event_target.rb', line 44

def self.from_event(event)
  _, target_type = TARGET_TYPES.find { |type, _| event.type.start_with?(type) }

  unless target_type
    raise UnexpectedEventType, "Unexpected event #{event.type}"
  end

  new(event.originating_event_id, target_type)
end

.workflowObject



40
41
42
# File 'lib/temporal/workflow/history/event_target.rb', line 40

def self.workflow
  @workflow ||= new(1, WORKFLOW_TYPE)
end

Instance Method Details

#==(other) ⇒ Object



61
62
63
# File 'lib/temporal/workflow/history/event_target.rb', line 61

def ==(other)
  id == other.id && type == other.type
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/temporal/workflow/history/event_target.rb', line 65

def eql?(other)
  self == other
end

#hashObject



69
70
71
# File 'lib/temporal/workflow/history/event_target.rb', line 69

def hash
  [id, type].hash
end

#to_sObject



73
74
75
# File 'lib/temporal/workflow/history/event_target.rb', line 73

def to_s
  "#{type} (#{id})"
end