Class: Temporalio::WorkflowHistory

Inherits:
Object
  • Object
show all
Defined in:
lib/temporalio/workflow_history.rb

Overview

Representation of a workflow’s history.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#eventsArray<Api::History::V1::HistoryEvent> (readonly)

Returns History events for the workflow.

Returns:



17
18
19
# File 'lib/temporalio/workflow_history.rb', line 17

def events
  @events
end

Class Method Details

.from_history_json(json) ⇒ WorkflowHistory

Convert a JSON string to workflow history. This supports the JSON format exported by Temporal UI and CLI.

Parameters:

  • json (String)

    JSON string.

Returns:



12
13
14
# File 'lib/temporalio/workflow_history.rb', line 12

def self.from_history_json(json)
  WorkflowHistory.new(Api::History::V1::History.decode_json(json).events.to_a)
end

Instance Method Details

#==(other) ⇒ Boolean

Compare history.

Parameters:

Returns:

  • (Boolean)

    True if equal.



43
44
45
# File 'lib/temporalio/workflow_history.rb', line 43

def ==(other)
  other.is_a?(WorkflowHistory) && events == other.events
end

#to_history_jsonString

Convert to history JSON.

Returns:

  • (String)

    JSON string.



35
36
37
# File 'lib/temporalio/workflow_history.rb', line 35

def to_history_json
  Api::History::V1::History.encode_json(Api::History::V1::History.new(events:))
end

#workflow_idString

Returns ID of the workflow, extracted from the first event.

Returns:

  • (String)

    ID of the workflow, extracted from the first event.



25
26
27
28
29
30
# File 'lib/temporalio/workflow_history.rb', line 25

def workflow_id
  start = events.first&.workflow_execution_started_event_attributes
  raise 'First event not a start event' if start.nil?

  start.workflow_id
end