Temporalex.History (Temporalex v0.5.4)

Copy Markdown View Source

A workflow's event history, parsed.

Returned by Temporalex.Client.fetch_workflow_history/2. Events carry Temporal's full record of one execution: every start, schedule, completion, failure, signal, and timer, in order.

{:ok, history} = Temporalex.Client.fetch_workflow_history(handle)

history.events
#=> [%Temporalex.History.Event{id: 1, type: :workflow_execution_started, ...}, ...]

Temporalex.History.stuck_reason(history)
#=> %{message: "replay command mismatch...", cause: ..., event_id: 17}

stuck_reason/1 answers the operational question directly: a workflow sitting Running with a retrying workflow task records each failed attempt as a :workflow_task_failed event — nondeterminism after a bad deploy being the classic cause — and this surfaces the latest one without the temporal CLI or the Web UI.

Event attributes are the transport-shaped maps of the corresponding Temporal event-attributes message (payload fields stay encoded); the type is the event's kind as a readable atom, e.g. :activity_task_scheduled. Treat attributes as an escape hatch, not a contract: field names follow Temporal's protos and may shift with them — the helpers on this module (events/2, last/2, stuck_reason/1) are the supported surface.

Summary

Functions

All events of one type, in order.

The last event of one type, or nil.

Why the workflow is stuck — the latest failed workflow task's failure.

Types

t()

@type t() :: %Temporalex.History{
  events: [Temporalex.History.Event.t()],
  run_id: String.t() | nil,
  workflow_id: String.t()
}

Functions

events(history, type)

@spec events(t(), atom()) :: [Temporalex.History.Event.t()]

All events of one type, in order.

last(history, type)

@spec last(t(), atom()) :: Temporalex.History.Event.t() | nil

The last event of one type, or nil.

stuck_reason(history)

@spec stuck_reason(t()) ::
  %{message: String.t() | nil, cause: term(), event_id: term()} | nil

Why the workflow is stuck — the latest failed workflow task's failure.

Returns nil when no workflow task has failed. A non-nil reason on a Running workflow means the server is retrying a task the worker cannot complete: nondeterminism after a code change is the classic cause, and message carries the worker's own report of it.