Durable.Query (Durable v0.1.0-rc)

View Source

Query functions for workflow executions.

Summary

Functions

Returns a %{parent_workflow_id => child_count} map for the given parent ids, in a single query. Used to render a "N children" drill-down affordance on top-level run rows without an N+1. Parents with no children are omitted.

Counts workflow executions matching filters.

Returns workflow execution counts grouped by status.

Gets a workflow execution by ID.

Gets step executions for a workflow.

Gets logs for a specific step.

Lists child workflow executions for a parent workflow.

Lists workflow executions with optional filters.

Lists workflow executions with total count for pagination.

Lists distinct workflow definitions, derived from execution history.

Functions

child_counts(parent_ids, opts \\ [])

@spec child_counts(
  [String.t()],
  keyword()
) :: %{required(String.t()) => non_neg_integer()}

Returns a %{parent_workflow_id => child_count} map for the given parent ids, in a single query. Used to render a "N children" drill-down affordance on top-level run rows without an N+1. Parents with no children are omitted.

Options

  • :durable - The Durable instance name (default: Durable)

count_executions(filters \\ [])

@spec count_executions(keyword()) :: non_neg_integer()

Counts workflow executions matching filters.

dashboard_counts(opts \\ [])

@spec dashboard_counts(keyword()) :: %{required(atom()) => non_neg_integer()}

Returns workflow execution counts grouped by status.

Returns a map like %{pending: 5, running: 3, completed: 100, ...}.

Options

  • :durable - The Durable instance name (default: Durable)

get_execution(workflow_id, opts \\ [])

@spec get_execution(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, :not_found}

Gets a workflow execution by ID.

Options

  • :include_steps - Include step executions (default: false)
  • :include_logs - Include logs in step executions (default: false)
  • :durable - The Durable instance name (default: Durable)

get_step_executions(workflow_id, opts \\ [])

@spec get_step_executions(
  String.t(),
  keyword()
) :: [map()]

Gets step executions for a workflow.

get_step_logs(workflow_id, step_name, opts \\ [])

@spec get_step_logs(String.t(), atom() | String.t(), keyword()) ::
  {:ok, [map()]} | {:error, :not_found}

Gets logs for a specific step.

list_child_executions(parent_workflow_id, opts \\ [])

@spec list_child_executions(
  String.t(),
  keyword()
) :: [map()]

Lists child workflow executions for a parent workflow.

Options

  • :status - Filter by status
  • :durable - The Durable instance name (default: Durable)

list_executions(filters \\ [])

@spec list_executions(keyword()) :: [map()]

Lists workflow executions with optional filters.

Filters

  • :workflow - Filter by workflow module
  • :workflow_name - Filter by workflow name
  • :status - Filter by status
  • :queue - Filter by queue
  • :limit - Maximum results (default: 50)
  • :offset - Offset for pagination (default: 0)
  • :durable - The Durable instance name (default: Durable)

list_executions_with_total(filters \\ [])

@spec list_executions_with_total(keyword()) :: {[map()], non_neg_integer()}

Lists workflow executions with total count for pagination.

Returns {executions, total_count}.

Accepts the same filters as list_executions/1.

list_workflows(opts \\ [])

@spec list_workflows(keyword()) :: [map()]

Lists distinct workflow definitions, derived from execution history.

Returns one row per {workflow_module, workflow_name} pair that has ever been executed, with aggregate stats. There is no compile-time registry of definitions in the engine — the executor only resolves modules by name on demand — so the dashboard derives the catalog from the persisted executions.

Each row contains:

  • :workflow_module (string)
  • :workflow_name (string)
  • :total_runs (non_neg_integer)
  • :running_count (non_neg_integer)
  • :waiting_count (non_neg_integer)
  • :failed_count (non_neg_integer)
  • :last_run_at (DateTime.t() | nil) — most recent inserted_at

  • :last_status (atom | nil) — status of the most recent run

Sorted by last_run_at DESC NULLS LAST.

Options

  • :durable - The Durable instance name (default: Durable)