PgFlow.Definitions (PgFlow v0.3.3)

Copy Markdown View Source

Typed operational reads for persisted PgFlow definitions and schedules.

Definition statistics use an explicit 24-hour window. List queries page the stored definitions before aggregating runs and steps for only that page.

Calculating next_run_at for a non-UTC cron.timezone requires the host application to configure an IANA-compatible Calendar.TimeZoneDatabase. When the database timezone cannot be resolved, next_run_at is nil.

Summary

Functions

Counts scheduled PgFlow definitions.

Counts stored flow definitions.

Counts stored job definitions.

Gets a scheduled definition with its stored schedule and operational data.

Gets a stored flow definition with its 24-hour operational statistics.

Gets a stored job definition with its 24-hour operational statistics.

Gets a step using its complete composite key.

Lists scheduled definitions in deterministic slug order.

Lists dependency rows for a flow using the complete composite key.

Lists stored flow definitions in deterministic slug order.

Lists stored job definitions in deterministic slug order.

Lists every stored step for a flow in execution order.

Unschedules the pg_cron entry for a PgFlow definition.

Functions

count_crons(repo)

@spec count_crons(module()) :: {:ok, non_neg_integer()} | {:error, term()}

Counts scheduled PgFlow definitions.

count_flows(repo)

@spec count_flows(module()) :: {:ok, non_neg_integer()}

Counts stored flow definitions.

count_jobs(repo)

@spec count_jobs(module()) :: {:ok, non_neg_integer()}

Counts stored job definitions.

get_cron(repo, flow_slug)

@spec get_cron(module(), String.t()) ::
  {:ok, PgFlow.CronSummary.t()} | {:error, :not_found | term()}

Gets a scheduled definition with its stored schedule and operational data.

get_flow(repo, flow_slug)

@spec get_flow(module(), String.t()) ::
  {:ok, PgFlow.DefinitionSummary.t()} | {:error, :not_found}

Gets a stored flow definition with its 24-hour operational statistics.

get_job(repo, flow_slug)

@spec get_job(module(), String.t()) ::
  {:ok, PgFlow.DefinitionSummary.t()} | {:error, :not_found}

Gets a stored job definition with its 24-hour operational statistics.

get_step(repo, flow_slug, step_slug)

@spec get_step(module(), String.t(), String.t()) ::
  {:ok, PgFlow.Schema.Step.t()} | {:error, :not_found}

Gets a step using its complete composite key.

list_crons(repo, opts \\ [])

@spec list_crons(
  module(),
  keyword()
) :: {:ok, [PgFlow.CronSummary.t()]} | {:error, term()}

Lists scheduled definitions in deterministic slug order.

Supported options are :cursor and :limit.

list_deps(repo, flow_slug)

@spec list_deps(module(), String.t()) :: {:ok, [PgFlow.Schema.Dep.t()]}

Lists dependency rows for a flow using the complete composite key.

list_flows(repo, opts \\ [])

@spec list_flows(
  module(),
  keyword()
) :: {:ok, [PgFlow.DefinitionSummary.t()]}

Lists stored flow definitions in deterministic slug order.

Supported options are :cursor and :limit.

list_jobs(repo, opts \\ [])

@spec list_jobs(
  module(),
  keyword()
) :: {:ok, [PgFlow.DefinitionSummary.t()]}

Lists stored job definitions in deterministic slug order.

Supported options are :cursor and :limit.

list_steps(repo, flow_slug)

@spec list_steps(module(), String.t()) :: {:ok, [PgFlow.Schema.Step.t()]}

Lists every stored step for a flow in execution order.

unschedule(repo, flow_slug)

@spec unschedule(module(), String.t() | atom()) ::
  :ok | {:error, :invalid_flow_slug | :not_owned | term()}

Unschedules the pg_cron entry for a PgFlow definition.

An absent schedule is a successful no-op, and a dangling pgflow:<slug> schedule whose stored flow definition is missing is also removed.

Schedule ownership is preserved: only entries owned by the current database role are removed, including when the caller is a superuser. When a pgflow:<slug> schedule remains visible under another role afterwards, the schedule keeps firing and {:error, :not_owned} is returned. Row-level security on cron.job hides other roles' schedules from regular roles, so only callers that can see the surviving entry (such as superusers) receive the error.