Skip to main content

remote_rerun

Remote rerun requests: parsing, freshness and the kinds a pod can perform.

A remote rerun request is a message from the Hub asking a pod to rerun some of its work. The pod, not the sender, decides the scope, cooldown and reason for each kind; the message only names the kind and carries its parameters.

The message body is plain JSON, RerunRequestedBody:

{
"datasource_name": ...,
"keyId": ...,
"signedPayload": {"encryptedRequest": <b64>, "signature": <b64>}
}

signedPayload is signed by a Hub signing key and encrypted to the pod's public key, exactly as for JOB_REQUEST_FROM_HUB (see bitfount.federated.hub_trigger). Once HubTriggerVerifier.verify_payload has opened it, the inner mapping parses into RerunRequestedPayload. Only that inner payload is integrity-protected, so it is the source of everything the pod acts on, including the requested_at that freshness is measured against.

To add a kind, write a function matching RemoteRerun that validates its params and records the rerun, then register it in REMOTE_RERUN_KINDS.

Module​

Functions​

is_fresh​

def is_fresh(    timestamp: str,    *,    now: datetime,    max_age: timedelta = datetime.timedelta(seconds=3600),) ‑> bool:

Return whether a request's timestamp is recent enough to act on.

A naive timestamp is read as UTC and one in the future counts as fresh, so clock skew between sender and pod does not drop requests.

Arguments

  • timestamp: The ISO 8601 timestamp, the signed requested_at.
  • now: The current time (aware).
  • max_age: How old a timestamp may be.

Returns True if the timestamp is parseable and at most max_age old.

perform_remote_rerun​

def perform_remote_rerun(    cache: CacheProtocol, payload: RerunRequestedPayload, *, now: datetime,) ‑> RerunRequestOutcome:

Perform the rerun a payload asks for.

Arguments

  • cache: The pod's background cache.
  • payload: The parsed request.
  • now: The current time (aware UTC).

Returns The outcome of the rerun.

Raises

  • InvalidRerunRequestError: If the kind is unknown or its params are invalid for that kind.

Classes​

InvalidRerunRequestError​

class InvalidRerunRequestError(*args, **kwargs):

A remote rerun request that cannot be acted on.

RerunRequestedBody​

class RerunRequestedBody(**data: Any):

Clear (unauthenticated) body of a rerun-requested message.

Only signed_payload is integrity-protected. datasource_name is a routing hint that must match the signed copy inside it, and key_id is only ever used as a JWKS lookup key.

Attributes

  • datasource_name: The datasource the request is addressed to.
  • key_id: kid of the Hub signing key to verify signed_payload against. Arrives on the wire as keyId.
  • signed_payload: The signed, encrypted RerunRequestedPayload. Arrives on the wire as signedPayload.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Variables​

  • static datasource_name : str
  • static key_id : str
  • static model_config
  • static signed_payload : bitfount.federated.hub_trigger._SignedPayload

Static methods​


from_message_body​

def from_message_body(body: bytes) ‑> RerunRequestedBody:

Parse a message body.

Arguments

  • body: The JSON message body.

Returns The parsed body.

Raises

  • InvalidRerunRequestError: If the body is not a JSON object, lacks a string datasource_name or keyId or a signedPayload, or carries an undecodable base64 blob.

RerunRequestedPayload​

class RerunRequestedPayload(    datasource_name: str,    kind: str,    params: dict[str, Any],    requested_by: str | None,    requested_at: str,):

The signed request inside a rerun-requested message.

Attributes

  • datasource_name: The datasource the request is addressed to.
  • kind: The kind of rerun requested.
  • params: Kind-specific parameters; empty when none were sent.
  • requested_by: Who asked, if the sender said.
  • requested_at: When the Hub made the request, ISO 8601. Signed, so it is what freshness is measured against.

Variables​

  • datasource_name : str
  • kind : str
  • requested_at : str
  • requested_by : str | None

Static methods​


from_verified_payload​

def from_verified_payload(    data: Mapping[str, Any],) ‑> RerunRequestedPayload:

Parse the inner payload HubTriggerVerifier.verify_payload returned.

Arguments

  • data: The verified, unpacked inner payload.

Returns The parsed payload.

Raises

  • InvalidRerunRequestError: If datasource_name, kind or requested_at is missing or not a string, or params or requested_by is of the wrong type.