Skip to main content

patient_api

The patient-data API child.

Classes​

PatientApiChild​

class PatientApiChild(spec: ChildSpec, *, read_fullchain: Callable[[], str | None]):

The patient-data API child.

Remembers the certificate it was started with, so the compute can tell when a renewed one has landed that this child is not yet serving.

Healthy when its server answers /health successfully, whatever the body: over HTTPS, with a certificate whose chain verifies, if it was started with one; otherwise over plain HTTP on loopback, which is all it serves until a certificate arrives.

Arguments

  • spec: What to run as the patient API.
  • read_fullchain: Reads the servable certificate on disk, or None if there is none.

Variables​

  • static label : ClassVar[str] - What the child is called in logs, as in "the pod child".
  • static name : ClassVar[str] - What the child is called in the hub's compute heartbeat.
  • serving_fullchain : str | None - The certificate the child was last started with, if it had one.

Static methods​


orphan_answer​

def orphan_answer(port: int) ‑> collections.abc.Mapping[str, typing.Any] | None:

What a patient API server, from any build, answers on port.

Asked over plain HTTP and then over HTTPS, as the server answers on one or the other depending on whether it had a certificate. The certificate is not checked: this only asks what is there.

Arguments

  • port: The port to ask on.

Returns Its /health body, or None if nothing answers there as an API.

port​

def port() ‑> int:

The port the API serves on.

Methods​


check_health​

def check_health(self) ‑> ChildHealth:

Inherited from:

ChildProcess.check_health :

Check the child now, and keep the result for status().

A child that is not running is unhealthy without being asked. A result for a process that was stopped or replaced while it was being checked is returned but not kept.

Returns Whether the child is healthy, and why not if it is not.

clear_orphan​

def clear_orphan(self) ‑> int | None:

Inherited from:

ChildProcess.clear_orphan :

Clear the child's port of a child an earlier run left on it.

Done before every start, and safe to do at any other time: this child's own running process is never cleared, so a host may clear ahead of taking a lock it would otherwise hold throughout.

Returns The pid of the process cleared, or None if there was none.

Raises

  • ChildPortHeldError: If the port is held and could not be cleared.

is_alive​

def is_alive(self) ‑> bool:

Inherited from:

ChildProcess.is_alive :

Whether the child has been started and is still running.

kill​

def kill(self) ‑> None:

Inherited from:

ChildProcess.kill :

Kill the child at once, with none of the grace stop gives it.

For a child that has stopped answering: it will not shut down cleanly, and waiting for it would hold up everything else waiting on the compute's lock. Its process is kept, so it reads as exited until it is started again.

Reported as KILLED without a log line of its own: whoever decides a child is not worth waiting for says why in its own.

latest_health​

def latest_health(self) ‑> ChildHealth:

Inherited from:

ChildProcess.latest_health :

The child's health now, without probing it.

Its last check's result while it is running. A child that is not running is unhealthy whatever its last check said.

start​

def start(self) ‑> None:

Inherited from:

ChildProcess.start :

Start the child if it is not running.

A child an earlier run left on the port is cleared first (see orphans). A process that cannot be started leaves the last one, if it had one, in place: a child restarted after a crash still reads as exited, with its exit code, until a start succeeds.

Raises

  • ChildPortHeldError: If the child's port is held and could not be cleared, once reported.
  • Exception: Whatever starting the process raised, once reported.

status​

def status(self) ‑> ChildStatus:

Inherited from:

ChildProcess.status :

The child's state, from its process if it was ever started.

stop​

def stop(self) ‑> None:

Inherited from:

ChildProcess.stop :

Stop the child if it is running: ask, wait, then kill if it must.

Discards the process once stopped, so status() reports the child as never started rather than as crashed with its SIGTERM exit code -- a poll after a deliberate stop must read the same as one that never found a child, not as one that found a dead one.