subscription
azure_bootstrap.subscription
¶
Generic external-resource renewal loop pattern.
Generalized from the Microsoft Graph webhook subscription lifecycle but applicable to any resource that has an expiration and might be reaped upstream before its declared lifetime ends.
Sleep slices in the renewal loop are bounded at 5 s so SIGTERM lands promptly — Kubernetes default grace period is 30 s.
Classes:
| Name | Description |
|---|---|
SubscriptionGone |
The upstream resource is no longer there — caller should mint a fresh one. |
Functions:
| Name | Description |
|---|---|
ensure_resource |
Idempotent find-or-create. |
renewal_loop |
Long-running renewal thread body. Sleeps in ≤ 5 s slices. |
SubscriptionGone
¶
Bases: Exception
The upstream resource is no longer there — caller should mint a fresh one.
ensure_resource
¶
ensure_resource(*, operation: str, list_fn: Callable[[], list[RenewableResource[R]]], create_fn: Callable[[], RenewableResource[R]], match_fn: Callable[[RenewableResource[R]], bool] = lambda r: True) -> RenewableResource[R]
Idempotent find-or-create.
- Iterate the existing resources via
list_fn; return the first one matchingmatch_fn. - Otherwise, mint a new one via
create_fn.
Source code in azure_bootstrap/subscription/__init__.py
renewal_loop
¶
renewal_loop(resource: RenewableResource[R], *, stop_event: Event, renew_fn: Callable[[str], RenewableResource[R]], recreate_fn: Callable[[], RenewableResource[R]] | None = None, interval_seconds: float, operation: str, gone_exception: type[BaseException] = SubscriptionGone, counter_namespace: str = 'subscription') -> None
Long-running renewal thread body. Sleeps in ≤ 5 s slices.