Snodo.Extensions.Tasks.WorkExecutor behaviour (snodo_tasks v0.3.2)

Copy Markdown View Source

Application-owned execution boundary for serializable task work.

The durable record contains a Snodo.Extensions.Tasks.Work value rather than a process-local function. A runner resolves that value through a configured executor after every initial claim or recovery claim. Executor configuration uses {module, state} so applications can rebuild runtime state when their supervision tree restarts without placing it in the descriptor.

{:failed, error, status_message} is terminal. An executor opts into the descriptor's next persisted retry delay only by returning {:retry, error, status_message}. Exceptions, exits, and invalid outcomes are returned as invocation errors so the runner can fail closed.

Summary

Functions

Safely invokes an executor and validates its runner-compatible outcome.

Validates an executor reference and returns it unchanged.

Types

outcome()

@type outcome() ::
  {:completed, map()}
  | {:failed, map(), String.t() | nil}
  | {:retry, map(), String.t() | nil}

ref()

@type ref() :: {module(), term()}

Callbacks

execute(t, t, state)

@callback execute(
  Snodo.Extensions.Tasks.Work.t(),
  Snodo.Cancellation.t(),
  state :: term()
) :: outcome()

Functions

invoke(executor, work, cancellation)

@spec invoke(ref(), Snodo.Extensions.Tasks.Work.t(), Snodo.Cancellation.t()) ::
  {:ok, outcome()} | {:error, term()}

Safely invokes an executor and validates its runner-compatible outcome.

validate_ref!(ref)

@spec validate_ref!(term()) :: ref()

Validates an executor reference and returns it unchanged.