Class: Cadence::Workflow::History::EventTarget

Inherits:
Object
  • Object
show all
Defined in:
lib/cadence/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 =
{
  'ActivityTask'                           => ACTIVITY_TYPE,
  'ActivityTaskCancel'                     => CANCEL_ACTIVITY_REQUEST_TYPE,
  'RequestCancelActivityTask'              => CANCEL_ACTIVITY_REQUEST_TYPE,
  'Timer'                                  => TIMER_TYPE,
  'CancelTimer'                            => CANCEL_TIMER_REQUEST_TYPE,
  'ChildWorkflowExecution'                 => CHILD_WORKFLOW_TYPE,
  'StartChildWorkflowExecution'            => CHILD_WORKFLOW_TYPE,
  'Marker'                                 => MARKER_TYPE,
  'ExternalWorkflowExecution'              => EXTERNAL_WORKFLOW_TYPE,
  'SignalExternalWorkflowExecution'        => EXTERNAL_WORKFLOW_TYPE,
  'ExternalWorkflowExecutionCancel'        => CANCEL_EXTERNAL_WORKFLOW_REQUEST_TYPE,
  'RequestCancelExternalWorkflowExecution' => CANCEL_EXTERNAL_WORKFLOW_REQUEST_TYPE,
  'UpsertWorkflowSearchAttributes'         => WORKFLOW_TYPE,
  'WorkflowExecution'                      => WORKFLOW_TYPE,
  'WorkflowExecutionCancel'                => 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/cadence/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/cadence/workflow/history/event_target.rb', line 38

def id
  @id
end

#typeObject (readonly)

Returns the value of attribute type.



38
39
40
# File 'lib/cadence/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/cadence/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.decision_id, target_type)
end

.workflowObject



40
41
42
# File 'lib/cadence/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/cadence/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/cadence/workflow/history/event_target.rb', line 65

def eql?(other)
  self == other
end

#hashObject



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

def hash
  [id, type].hash
end

#to_sObject



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

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