← all modules

Std.Durable

Std.Durable

Types
  type Ctx
  type WorkflowDef i o
  type RegisteredWorkflow
  type alias ResultRow = { result : String }
  type alias PayloadRow = { payload : String }
  type alias ClaimRow = { id : String , workflow : String , version : String , input : String }
  type VersionPolicy = FailSafe | PinToStart
  type SnapshotEvent model = Restored (Maybe model) | RestoreFailed Error | Persisted | PersistFailed Error

Values
  applyRestore : SnapshotEvent model -> model -> model
      Apply a `SnapshotEvent` in `update`: `Restored (Just m)` swaps in the restored
  awaitSignal : Ctx -> Codec a -> String -> Task Error a
      Suspend the run until a signal named `name` is delivered (by `signal`), then
  compact : Db -> Int -> Task Error Int
      Delete the journal + signal rows of TERMINAL runs (`done` / `dead` /
  conn : Ctx -> Db
      The database handle for this run, for a `step`'s own DB effects (so a
  deleteSnapshot : Db -> String -> Task Error ()
      Delete the snapshot of `runId`, if there is one. A run with no snapshot is
  erase : WorkflowDef i o -> RegisteredWorkflow
      The type-erased form of a workflow, for the runner's `poll` list.
  isSuspend : Error -> Bool
      Is this error the durable suspend sentinel (as opposed to a real failure)?
  loadSnapshot : Db -> String -> Codec a -> Task Error (Maybe a)
      Load the last snapshot for `runId`, decoded with `codec`. `Nothing` if the run
  poll : Db -> List RegisteredWorkflow -> Task Error Bool
      Claim one due run and advance it until it suspends or completes. Returns
  pollWith : Db -> VersionPolicy -> List RegisteredWorkflow -> Task Error Bool
      `poll` with an explicit `VersionPolicy`. `poll = pollWith FailSafe`.
  register : String -> Codec i -> Codec o -> (Ctx -> i -> Task Error o) -> WorkflowDef i o
      Register a workflow: a stable `name`, the input and output codecs, and the
  registerVersioned : String -> String -> Codec i -> Codec o -> (Ctx -> i -> Task Error o) -> WorkflowDef i o
      Register a workflow at an explicit VERSION. A run is stamped with the def's
  restoreCmd : Db -> String -> Codec model -> (SnapshotEvent model -> msg) -> Cmd msg
      A `Cmd` for the app's `init` that loads the last snapshot and delivers it as
  runId : Ctx -> String
      The id of the run this workflow body is executing under — the key passed to
  saveSnapshot : Db -> String -> Codec a -> Int -> a -> Task Error ()
      Persist a snapshot of a value (typically a TEA `Model`) for `runId`, keyed by
  saveSnapshotAuto : Db -> String -> Codec a -> a -> Task Error ()
      Like `saveSnapshot`, but the caller does not manage the `seq` — it is
  setup : Db -> Task Error ()
      Create the durable tables if they do not exist. Idempotent; call once at
  signal : Db -> String -> String -> Codec a -> a -> Task Error ()
      Deliver a named signal to a run, waking an `awaitSignal` that is blocked on
  sleep : Ctx -> String -> Int -> Task Error ()
      Suspend the run for `ms` from now, passively. On the first hit it records the
  snapshotCmd : Db -> String -> Codec model -> (SnapshotEvent model -> msg) -> model -> Cmd msg
      A `Cmd` for the app's `update` that snapshots the new model after a real
  start : Db -> WorkflowDef i o -> String -> i -> Task Error ()
      Start a workflow instance, keyed by `id` (the caller's idempotency key). A
  step : Ctx -> Codec a -> String -> Task Error a -> Task Error a
      Run a side-effecting `task` as a durable step, journalled under `stepId`. On
  stepValue : Ctx -> Codec a -> String -> (() -> a) -> Task Error a
      Journal a fresh, nondeterministic PURE value (a uuid, a timestamp) so it is