Skip to main content

admission

Whether the machine has room for one more background DAG run.

Every submitter of a background run — the rerun sweep's four checks, recovery's replays, an owed or listed run resubmitted — asks the same question before it schedules anything: are background_dag_max_concurrent_runs runs already executing on this machine? A run submitted on top of a full machine does no work. Its own subprocess comes up, takes its lineage, waits out background_machine_slot_wait for a slot, and ends Skipped (machine_busy) having started nothing, while the lineage it was for stays due and is submitted again on the next tick.

Answered here rather than at each call site, so the count and the wording a starved pod logs are the same whichever check did the asking. count_executing_background_dag_runs is the count itself; this adds the two things one tick needs on top of it — the runs the tick has already submitted, which Prefect may still show as SCHEDULED rather than new, and a count that could not be taken at all, which gates on nothing rather than on a guess: the in-flow machine slot still bounds what executes.

Classes​

MachineAdmission​

class MachineAdmission(    limit: int | None = None,    executing: int | None = None,    uncounted: bool = False,    submitted: int = 0,):

One tick's view of the machine's background-run capacity.

Attributes

  • limit: How many background DAG runs may execute at once (background_dag_max_concurrent_runs), or None to apply no limit.
  • executing: The count taken for this tick, or None until one is taken.
  • uncounted: A count was asked for and did not come back, so nothing is gated on what could not be read.
  • submitted: Runs this tick has submitted since that count was taken, which the count cannot show yet — a submitted run is SCHEDULED until its Runner picks it up, and two submitters counting the same Prefect at the same moment would each see room for the same slot.

Variables​

  • executing : int | None
  • limit : int | None
  • submitted : int
  • uncounted : bool

Static methods​


from_settings​

def from_settings() ‑> MachineAdmission:

Return an admission bounded by the configured machine limit.

Returns The admission, gating on background_dag_max_concurrent_runs.

Methods​


count​

async def count(self, client: PrefectClient) ‑> int | None:

Take, or re-read, the machine's executing-run count for this tick.

Asked at most once: the count a gate read is the count the next gate reads, so a tick that judges a dozen lineages costs one query rather than a dozen, and the answer cannot change underneath the tick.

Arguments

  • client: An open PrefectClient.

Returns The number of background DAG runs executing on the machine, or None when that could not be counted — in which case no further count is attempted this tick and a warning is logged once.

in_use​

async def in_use(self, client: PrefectClient) ‑> int:

Return how many runs count against the limit, counting if needed.

Arguments

  • client: An open PrefectClient.

Returns As for in_use_now, after a count if this tick has not taken one.

in_use_now​

def in_use_now(self) ‑> int:

Return how many runs count against the limit, from what is known now.

Synchronous, for a caller that has already counted — such as the resource line, which reports whether the pod is working and must not ask Prefect a second question to do it.

Returns The runs executing when the count was taken, plus the runs this tick has submitted since. The submitted runs alone when the count could not be taken.

note_submitted​

def note_submitted(self) ‑> None:

Record that this tick submitted a run, so the next gate sees it.

refusal​

async def refusal(self, client: PrefectClient) ‑> str | None:

Say why nothing may be submitted now, or return None if it may.

The one predicate every submitter gates on, and one wording: a pod starved by its own runs should read the same sentence from the rerun check as from recovery, saying how many runs are executing and the limit they are held against.

Arguments

  • client: An open PrefectClient.

Returns The account of the full machine — no trailing full stop, so a caller can put it mid-sentence — or None when there is room, or when no limit applies.