# `Continuum.Runtime.Journal`
[🔗](https://github.com/Yyeger/Continuum/blob/main/lib/continuum/runtime/journal.ex#L1)

Behaviour for the event-history journal.

Two adapters ship with v0.1:

  * `Continuum.Runtime.Journal.InMemory` — process-level state for tests and
    single-node hello-world. No durability.
  * `Continuum.Runtime.Journal.Postgres` — Ecto-backed durable journal with
    transactional appends and lease-token fencing.

All append operations carry a `lease_token` (or `nil` for unleased
in-memory / pre-dispatch execution). The Postgres adapter rejects writes
whose token does not match the run row's fencing token; `nil` only writes
to unleased rows.

# `append!`

```elixir
@callback append!(
  instance :: Continuum.Runtime.Instance.t(),
  run_id :: binary(),
  event :: map(),
  lease_token :: integer() | nil
) :: :ok
```

# `complete!`

```elixir
@callback complete!(
  instance :: Continuum.Runtime.Instance.t(),
  run_id :: binary(),
  result :: term(),
  lease_token :: integer() | nil
) :: :ok
```

# `fail!`

```elixir
@callback fail!(
  instance :: Continuum.Runtime.Instance.t(),
  run_id :: binary(),
  error :: term(),
  lease_token :: integer() | nil
) :: :ok
```

# `get_run`

```elixir
@callback get_run(instance :: Continuum.Runtime.Instance.t(), run_id :: binary()) ::
  nil | map()
```

Look up the run record. Returns `nil` if no such run, or a map with at
least `:state`, `:result`, `:error` keys (atoms / terms — already decoded).

# `load`

```elixir
@callback load(instance :: Continuum.Runtime.Instance.t(), run_id :: binary()) :: [map()]
```

# `load_with_snapshot`

```elixir
@callback load_with_snapshot(
  instance :: Continuum.Runtime.Instance.t(),
  run_id :: binary(),
  lease_token :: integer() | nil
) :: {Continuum.Snapshot.t() | nil, [map()]}
```

# `start_run`

```elixir
@callback start_run(
  instance :: Continuum.Runtime.Instance.t(),
  run_id :: binary(),
  workflow :: module(),
  input :: term()
) :: :ok | {:error, term()}
```

# `suspend!`

```elixir
@callback suspend!(
  instance :: Continuum.Runtime.Instance.t(),
  run_id :: binary(),
  lease_token :: integer() | nil
) :: :ok
```

# `take_snapshot!`

```elixir
@callback take_snapshot!(
  instance :: Continuum.Runtime.Instance.t(),
  snapshot :: Continuum.Snapshot.t()
) :: :ok
```

# `default`

Returns the configured default journal adapter.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
