hub_project_view
What the Hub says about this user's projects.
Read by the periodic-rerun gates, by the task-definition check a background run's submission makes, and by file metadata indexing order, which all need the published, archived and linked state of every project the user can see, in one paged pass.
Module
Functions
fetch_hub_project_view
def fetch_hub_project_view( hub: BitfountHub, *, warn_key: tuple[str, ...] = ('pod_hub_projects',), consequence: str = 'the periodic rerun check is skipped, abandoning no lineage, and file metadata indexing skips no datasource',) ‑> HubProjectView | None:Return what the Hub says about this user's projects.
Paged in full rather than probed per lineage: one Hub round trip per check covers every candidate, and the page size the Hub defaults to (12) is smaller than a customer's project list.
Both numbers are returned, not just the published ids, because "the Hub
listed projects and none of them were published" is a distinct answer
from "the Hub listed nothing". The first is what a renamed or dropped
status field looks like, and on its own it would silence every rerun on
the pod with nothing above INFO to show for it.
The same pages also carry each project's linked datasets, so the link gate costs no extra round trip.
A failure is warned once per failure streak of warn_key, and the next success under that key ends the streak, so a caller with a key of its own neither starts nor ends another caller's streak.
Arguments
hub: The Hub to list projects from.warn_key: The process-scoped warn-once key the failure streak is kept under. The rerun sweep and indexing share the default.consequence: What the failure means for the caller, completing the warning's "not evidence that anything was archived or unlinked".
Returns
The view, or None when the Hub could not be reached — which is not
evidence that anything was deleted, so the caller must skip rather
than act on it.
hub_gate
def hub_gate(hub: HubProjectView, record: FlowSpecRecord) ‑> str | None:Return the Hub gate that refuses record's lineage, if any.
The two questions only the Hub can answer: whether the project is still
published, and whether the dataset is still linked to it. The project can
still be published while this dataset has been unlinked from it. Nothing
tells the pod that either happened — there is no unlink message and
flow_specs is never deleted from — so without this gate a lineage keeps
submitting its stored spec for ever, against a project that may no longer
grant what that spec pins.
Applied by the periodic rerun sweep before it submits a lineage, and by the task-definition check before it replaces one.
A project absent from HubProjectView.linked reported no linked_datasets
key, which is "not reported", not "none linked". Left ungated: an SDK that
refused on a key it cannot see would disable every lineage against an
older Hub.
Arguments
hub: The Hub's answer for this check.record: The lineage being judged.
Returns
"hub_project_unpublished" when the project is not published,
"hub_dataset_unlinked" when the Hub reports the project's links and this
dataset is not among them, else None.
linked_names_for_owner
def linked_names_for_owner( view: HubProjectView, owner: str, lineages: Iterable[tuple[str, str]],) ‑> dict[str, set[str]]:Return the dataset names linked to each project, whoever owns them.
Only projects whose Hub payload carried a linked_datasets key appear: a
project absent from the view's links is absent here, never an empty set,
so a Hub that does not report links records nothing against it.
A name the Hub lists for a project counts as linked whichever owner it
reports. The owner match fails open: nothing checks that the Hub's
ownerUsername is this pod's username, and reading a mismatch as an unlink
would take the dataset's patients out of the trial. So for each lineage in
lineages whose name the project's owner-aware links hold only under other
owners (none under owner, none with no owner), a WARNING names the
project, the dataset and the owners seen, once per process for each pair.
Arguments
view: What the Hub reported about this user's projects.owner: The username that owns this pod's datasets.lineages: This pod's(project_id, datasource_name)pairs, the only ones an owner mismatch is reported for.
Returns The linked dataset names, by project id.
record_hub_link_report
def record_hub_link_report( cache: CacheProtocol, view: HubProjectView, owner: str,) ‑> set[tuple[str, str]]:Fold the Hub's linked datasets into the link state of stored lineages.
Judges every lineage in flow_specs against the projects the view reports
links for, by dataset name whatever owner the Hub reports
(linked_names_for_owner), and logs each pair that newly became unlinked.
A new unlink does not count until later reports have kept it for
UNLINK_GRACE_PERIOD.
Arguments
cache: An open background cache.view: What the Hub reported about this user's projects.owner: The username that owns this pod's datasets.
Returns
The (project_id, datasource_name) pairs that became unlinked.
Classes
HubProjectView
class HubProjectView( published: set[str], listed: int, linked: dict[str, set[str]], archived: set[str] = set(), linked_by_owner: dict[str, set[tuple[str | None, str]]] = {},):One rerun check's answer from the Hub about this user's projects.
Arguments
published: Ids of the projects the Hub reports as published.listed: How many projects the Hub returned at all, published or not. Kept because an empty published set has two readings — every project genuinely unpublished, or thestatusfield this SDK filters on no longer meaning what it did — and only this number tells them apart.linked: Project id -> the dataset names the Hub reports linked to it. A project is absent from this map when its payload carried nolinked_datasetskey at all, which is a different answer from an empty set: the first means the Hub does not report links, the second that the project has none. The gate acts only on the second.archived: Ids of the projects the Hub reports as archived. Not the complement of published: the Hub's status is nullable, and a project with no status is not archived.linked_by_owner: Project id ->(owner username, dataset name)of each linked dataset. linked drops the owner, and a project can link other users' datasets of the same name as this pod's.
Variables
-
archived : set[str]
-
linked : dict[str, set[str]]
-
linked_by_owner : dict[str, set[tuple[str | None, str]]]
-
listed : int
-
published : set[str]