Skip to main content

lineage_facts

What the scheduler and recovery know about a lineage, read from its runs.

A lineage is one (task_hash, dag, project_id). Everything the rerun scheduler needs to decide whether to submit a run of it is derived here from the rows its runs wrote about themselves (bitfount.flows.dag.run_row) and the metadata markers; nothing is written back. The scheduler predicts nothing: a run records what it did, and the next decision reads it.

The facts:

  • last_rerun_at — when a rerun last committed: passed setup's gates and went on to plan. A rerun that stood down, or was turned away before its gates, has not spent its occurrence; one that failed has, gates or not, which is why setup stamps the failing exit too — an unspent occurrence is due again on the next tick. Read off the row's committed_at, not its started_at: the row opens before the run waits for its machine slot, so a run that waited across a cron occurrence would date itself to the one before it, and the occurrence it is about to serve would look unspent.
  • attempts_since_progress — how many runs have failed, or committed and then not moved the sweep forward, since the last run that did, counting back no further than a finished row that can say neither (one written before the tag existed, or one a CLI entry point closed without an outcome). The one give-up bound: growth, the wave continuation, the refresh and recovery all read it. A run whose process died counts once recovery closes its row, which is why that close records whether the run moved the sweep. A stand-down, a gate skip and an outage (partial) are not attempts.
  • held_by — the stand-down the lineage's last run recorded, while what it waits for has not happened: no_scan_coverage until a scan sweep newer than the row, candidates_exhausted until an index walk newer than it or, for a run that read an EHR listing, a newer complete snapshot of that listing.
  • last_hold_at — when the lineage was last held by any stand-down or turned away by a lock gate, so a cron occurrence held through its grace window is still owed once the hold lifts. A hold the rerun check recorded itself, with no run to date a row — a machine too full to submit the run for it (record_hold) — comes from the lineage's stored tags instead, and the later of the two is the answer.
  • owed — a link, recovery replay, listing pickup or task-definition update a lock gate turned away, whose work no later run has carried: the scheduler resubmits it once its gates allow. Owed per piece of work, a (trigger, monitor_task_id), so a rerun that gets past its gates does not stand in for a link's run, nor that for the pickup a completed EHR listing released. A task-definition update belongs here although it is a rerun: it is a message delivered once, so unlike a periodic rerun it is not found due again by itself.

Module​

Functions​

dag_name_of​

def dag_name_of(record: FlowSpecRecord) ‑> str | None:

Return the DAG record's spec runs, its rows' type.

Arguments

  • record: The lineage's persisted replay material.

Returns The DAG's name, or None when the spec no longer loads.

facts_for_record​

def facts_for_record(    cache: CacheProtocol, record: FlowSpecRecord, *, pod_name: str,) ‑> LineageFacts:

Read the facts of the lineage record stores the replay material of.

Blocking: it reads the cache. A spec that no longer loads names no DAG and so no rows; such a lineage reads as having none, and says so (attempts_known), because "no rows to count" and "no attempt yet" are otherwise the same zero.

Arguments

  • cache: The pod's background cache.
  • record: The lineage's persisted replay material.
  • pod_name: The pod the lineage runs on, which keys its task hash.

Returns The facts.

lineage_facts​

def lineage_facts(    cache: CacheProtocol,    *,    task_hash: str,    dag_name: str,    project_id: str | None,    legacy_last_rerun_at: datetime | None = None,    stamped_last_hold_at: datetime | None = None,) ‑> LineageFacts:

Read the lineage's facts from its rows.

Never raises: a cache that cannot be read answers as a lineage with no rows, which errs toward running it — but its attempts are then unknown (attempts_known), since that zero is "nothing could be read" rather than "no attempt yet".

Arguments

  • cache: The pod's background cache.
  • task_hash: The datasource-level task hash.
  • dag_name: The DAG the lineage runs; its rows' type.
  • project_id: The lineage's project, or None.
  • legacy_last_rerun_at: The rerun stamp a build before the rows carried it wrote to flow_specs, read only when no committed rerun row exists. A pod upgraded mid-calendar would otherwise find every lineage due at once.
  • stamped_last_hold_at: The hold the rerun check recorded on the flow_specs row itself (record_hold), read from the record rather than from a row because no run was submitted to hold. The later of it and the newest row-recording hold is the lineage's.

Returns The facts.

Global variables​

  • HOLD_STOP_REASONS - The stop_reasons of a run that stood down for something that has to change before a run of its lineage could do otherwise.

Classes​

LineageFacts​

class LineageFacts(    last_rerun_at: datetime | None,    attempts_since_progress: int,    held_by: str | None,    last_hold_at: datetime | None,    owed: OwedWork | None = None,    attempts_known: bool = True,):

What a lineage's runs say about it; see the module docstring.

Attributes

  • last_rerun_at: When a rerun of the lineage last committed, or None.
  • attempts_since_progress: Failed or unproductive committed runs since the last run that moved the sweep forward.
  • held_by: The stand-down still holding the lineage, or None.
  • last_hold_at: When the lineage was last held by a stand-down or turned away by a lock gate, or None.
  • owed: The oldest-due work a gate turned away and no run has carried since, or None.
  • attempts_known: Whether attempts_since_progress was read from the lineage's rows. False when nothing named them — a stored spec that no longer loads, or a cache that could not be read: the count is zero because nothing could be read, not because nothing failed, and a reader must not take it as headroom under its limit.

Variables​

  • attempts_known : bool
  • attempts_since_progress : int
  • held_by : str | None

OwedWork​

class OwedWork(    trigger: BackgroundTrigger,    attempt: int,    monitor_task_id: str,    is_rerun: bool | None,    reason: str,    due_at: datetime,    refused_at: datetime,):

A link or replay a lock gate turned away, still owed its run.

Attributes

  • trigger: Why the work was submitted: LINK, RECOVERY, EHR_LISTING_READY or TASK_DEFINITION_UPDATED.
  • attempt: The turned-away run's attempt, resubmitted as is.
  • monitor_task_id: The Hub task the work reports to; with trigger, what identifies the work.
  • is_rerun: Whether the turned-away run applied rerun semantics, or None when its row does not say.
  • reason: The gate that last turned it away.
  • due_at: When the work first became due: the oldest row of its unbroken run of refusals.
  • refused_at: When it was last turned away.

Variables​

  • attempt : int
  • is_rerun : bool | None
  • monitor_task_id : str
  • reason : str