Skip to content
Français

createRunObserver

import { createRunObserver } from "@elie-laloum/outpost/observation";

Create a transport-backed receiver for one dispatch or workflow under a caller-selected ID. Conditional writes reject duplicate IDs and fence stale writers. Periodic heartbeats stop on settlement, storage failure or close. Resume appends only to settled workflow projections with a fresh hub; unsettled records require a new ID after explicit execution recovery. Observation failures remain isolated from execution.

Complete example and detailed rules.

  • optionsRequired
    RunObserverOptions
    Transport, execution ID, projection kind, heartbeat policy and optional settled-workflow resume.
  • options.transporterRequired
    Transport
    Transport owning run snapshots and immutable event segments; caller owns its credentials and lifecycle.
  • options.idRequired
    string
    Unique ID of at most 128 characters in one safe transport key segment.
  • options.kindRequired
    "workflow" | "dispatch"
    Choose dispatch for one request or workflow for one task graph.
  • options.heartbeatMsOptional
    number | undefined
    Heartbeat period in milliseconds, default 5000; positive and less than abandonAfterMs.
  • options.abandonAfterMsOptional
    number | undefined
    Suspected abandonment delay in milliseconds, default 30000, strictly greater than heartbeatMs.
  • options.resumeOptional
    boolean | undefined
    Explicitly append to a settled workflow record with a fresh hub; duplicate creation and unsettled takeover remain refused.

Promise<RunObserver>

export declare function createRunObserver(
  options: RunObserverOptions,
): Promise<RunObserver>;