Skip to main content

run_row

The runs row a background DAG run writes about itself.

One row per background flow run, and the row is the run's record: opened by the flow body as soon as it knows which DAG it runs, committed by setup once the run's gates have passed, and closed by the flow body on every exit. What the rerun scheduler and recovery need to know about a lineage is read back from these rows (bitfount.flows.dag.lineage_facts), so nothing here is optional and nothing else writes the same facts elsewhere.

The row's tags carry what the run was:

  • trigger, is_rerun, attempt, monitor_task_id — written at open.
  • committed and committed_at — written by setup after its gates, before planning. A rerun that got this far has spent its occurrence; one that stood down has not. committed_at is when, and it is not the row's started_at: the row opens before the run waits for its machine slot, so a run that waited across a cron occurrence would otherwise look like it belonged to the one before.
  • stop_reason — why the run ended without carrying its work, if it did.
  • made_progress — whether the run moved its lineage's sweep forward.

Module​

Functions​

close_background_run​

def close_background_run(    cache: CacheProtocol,    run_id: str,    *,    failed: bool,    error: str | None = None,    stop_reason: str | None = None,    made_progress: bool = False,) ‑> None:

Close the run's row on the way out of the flow body. Never raises.

Ends the row if nothing ended it first — a run that died in its own bookkeeping, or before setup wired a notifier — and merges what the run has to say about itself either way.

Arguments

  • cache: The pod's background cache.
  • run_id: The run's row.
  • failed: Whether the run raised.
  • error: What it raised, for the row.
  • stop_reason: Why the run ended without carrying its work, if it did.
  • made_progress: Whether the run moved its lineage's sweep forward.

commit_background_run​

def commit_background_run(cache: CacheProtocol, run_id: str) ‑> None:

Record that the run spent its cron occurrence: setup's gates passed.

Stamps when as well as whether: the row's started_at is written when the run opens its row, which is before it waits for its machine slot, so it cannot date the occurrence this run spends. committed_at can, and is what lineage_facts.last_rerun_at reads.

Setup also calls this on the way out of a failing exit, the gates reached or not, and that is the intended meaning: what the stamp is read for is spending the occurrence, and a run that failed has spent it. Without it the rerun scheduler keeps finding the lineage due for the same occurrence and resubmits it on every tick, up to background_run_failure_limit runs of whatever the failure costs each — three wedged setups, for the one this was last extended for.

Idempotent in the flag; the stamp of a second call would be a second gate pass, which does not happen (setup calls this once).

Arguments

  • cache: The pod's background cache.
  • run_id: The run's row.

open_background_run​

def open_background_run(    cache: CacheProtocol,    *,    task_hash: str,    dag_name: str,    project_id: str,    run_id: str,    trigger: BackgroundTrigger,    is_rerun: bool,    attempt: int,    monitor_task_id: str,) ‑> str:

Open the run's row, before anything the run does can fail.

Pure bookkeeping (dedup=False): whether the run may execute is its lock's decision, not the row's.

Arguments

  • cache: The pod's background cache.
  • task_hash: The (pod, datasource) task hash.
  • dag_name: The DAG the run executes; the row's type.
  • project_id: The lineage's project.
  • run_id: The id the pod minted for this run.
  • trigger: Why the run was started.
  • is_rerun: Whether the run carries rerun semantics.
  • attempt: The run's position in its recovery lineage.
  • monitor_task_id: The Hub monitor task the run reports under.

Returns The row's run id.

Raises

  • ValueError: If no row was inserted, which dedup=False rules out.

own_attempt​

def own_attempt() ‑> int:

Return this flow run's position in its recovery lineage, from its tags.

Returns The attempt: tag's value, or 1 outside a flow run or without the tag.

Global variables​

  • ATTEMPT_TAG - The run's position in its recovery lineage.
  • COMMITTED_AT_TAG - When setup's gates passed, as an ISO-8601 UTC timestamp.
  • COMMITTED_TAG - Whether setup's gates passed: the run went on to plan and execute.
  • IS_RERUN_TAG - Whether the run carries rerun semantics.
  • MADE_PROGRESS_TAG - Whether the run moved its lineage's sweep forward.
  • MONITOR_TASK_ID_TAG - The Hub monitor task the run reported under.
  • TRIGGER_TAG - Why the run was started, a BackgroundTrigger value.