restart
Deciding when a compute child that went down is started again.
Classes
RestartPolicy
class RestartPolicy( max_delay_seconds: int = 60, max_delay_before_ready_seconds: int | None = None, reset_after_seconds: float = 300.0, unhealthy_threshold: int | None = 3, unhealthy_only_after_ready: bool = False, crash_loop_failures: int | None = 10, config_error_exit_codes: frozenset[int] = frozenset(),):How a child that dies or stops answering is brought back.
It is never given up on, unless it exits saying its configuration is
invalid: the wait between restarts doubles from one second up to a cap
and stays there. A child that keeps failing is called a crash loop and
reported at ERROR, once every crash_loop_failures failures, but it is
still restarted.
Arguments
max_delay_seconds: The longest wait between restarts.max_delay_before_ready_seconds: The longest wait between restarts of a child that went down before it ever passed a health check: usually something outside it that it needs is not there yet.Noneusesmax_delay_seconds.reset_after_seconds: How long a restarted child must stay up for its next failure to start the wait from one second again.unhealthy_threshold: Failed health checks in a row after which a running child is killed and restarted.Nonenever restarts a child that is still running, however its checks go.unhealthy_only_after_ready: Whetherunhealthy_thresholdcounts only the checks failed since the child last passed one. A child that takes minutes to come up is not hung while it has never been ready, and killing it would only start the wait again; one that was ready and then stopped answering is hung.crash_loop_failures: Failures in a row at which the child is reported as crash looping, and at every multiple of it after that.Nonereports none. Nothing stops a child being restarted.config_error_exit_codes: Exit codes with which the child says its configuration is invalid. A child that exits with one is leftdown: started again as it is, it would fail the same way.
Variables
-
config_error_exit_codes : frozenset[int]
-
crash_loop_failures : int | None
-
max_delay_before_ready_seconds : int | None
-
max_delay_seconds : int
-
reset_after_seconds : float
-
unhealthy_only_after_ready : bool
-
unhealthy_threshold : int | None
Restarter
class Restarter(policy: RestartPolicy):One child's restart state under a RestartPolicy.
Decides only: when the next restart is due, whether a running child has failed enough health checks to be restarted, and what kind of failure an exit was. Starting and stopping the process is the child's job.
Times are time.monotonic() values passed in, so nothing here waits.
Arguments
policy: When and how often to restart.
Variables
crash_looping : bool- Whether the failures in a row have reached another crash-loop report.
failed_checks : int- Health checks of the running process failed in a row.
failures : int- Failures in a row, which set how long the next wait is.
hung : bool- Whether the running child has failed enough checks to be restarted.
restarts : int- Restarts since the child was last started deliberately.
scheduled : bool- Whether a restart is waiting to become due.
Methods
checked
def checked(self, *, healthy: bool) ‑> None:Note a health check of the running process.
Arguments
healthy: Whether it passed.
due
def due(self, now: float) ‑> bool:Whether the scheduled restart is due.
Arguments
now: The current time.
exit_kind
def exit_kind( self, exit_code: int | None,) ‑> bitfount.telemetry.logs.models.ComputeChildExitKind:What kind of failure the child going down was.
Arguments
exit_code: How its process ended, orNoneif it failed to start.
reset
def reset(self) ‑> None:Forget all of it, for a deliberate start.
restarting
def restarting(self) ‑> int:Note that the scheduled restart is being made.
Returns Which restart this is, counting from one.
schedule
def schedule(self, now: float) ‑> int:Count a failure and schedule the next restart.
Arguments
now: The current time.
Returns How many seconds until it is due.
started
def started(self, now: float) ‑> None:Note that a new process has started.
Arguments
now: When it started.
still_running
def still_running(self, now: float) ‑> None:Note that the child is still running.
Once it has been up for the policy's reset_after_seconds, its backoff
is cleared, so its next failure waits one second again.
Arguments
now: The current time.
stopped
def stopped(self) ‑> None:Note a deliberate stop: nothing is to be restarted.