Continuum.Runtime.Lease (continuum v0.5.0)

Copy Markdown View Source

Postgres lease acquisition and renewal for workflow runs.

The lease token is the fencing token used by the Postgres journal. Acquiring a lease performs the roadmap's UPDATE ... RETURNING CAS: only unowned or expired running runs can be claimed, and every successful claim receives a fresh monotonic token from continuum_lease_token_seq.

Summary

Functions

Acquire a lease for a running or suspended run.

Acquire a lease or raise.

Build the owner string used in lease rows.

Renew a lease by owner and token.

Types

t()

@type t() :: %Continuum.Runtime.Lease{
  owner: binary(),
  run_id: binary(),
  token: integer()
}

Functions

acquire(run_id, opts \\ [])

@spec acquire(
  binary(),
  keyword()
) :: {:ok, t()} | {:error, term()}

Acquire a lease for a running or suspended run.

Returns {:error, :not_acquired} when another owner still holds the lease.

acquire!(run_id, opts \\ [])

@spec acquire!(
  binary(),
  keyword()
) :: t()

Acquire a lease or raise.

owner()

@spec owner() :: binary()

Build the owner string used in lease rows.

owner(instance_name)

renew(run_id, owner, token, opts \\ [])

@spec renew(binary(), binary(), integer(), keyword()) ::
  :ok | {:error, :lost} | {:error, term()}

Renew a lease by owner and token.

Returns {:error, :lost} when the row is gone or the owner/token no longer match, which means another process acquired the fencing token.