archivebox.core.takeover_util
Coordinate local foreground processes without pretending to provide a distributed lock.
ArchiveBox wants one orchestrator per collection, but Process rows can only prove
liveness for PIDs visible on the current machine/PID namespace. We therefore
enforce one active runner per (Machine, DATA_DIR) locally, retire stale rows
from sequential containers on that machine, and only warn about rows owned by a
different machine. Foreign-machine rows must never block progress or be killed:
multi-machine coordination belongs in the Crawl/Snapshot CAS claim layer, not in
process takeover.
These helpers only hand local supervisord/runner ownership between CLI parents. They must not hold database transactions or filesystem locks while work runs.
Module Contents
Functions
Return the live local parent allowed to own the server runtime stack. |
|
Return the newest live local parent allowed to borrow runner/sonic. |
|
Return locally verifiable runners and warn about unsupported overlap. |
|
Admit one active runner for this Machine and DATA_DIR using Process rows. |
|
Data
API
- archivebox.core.takeover_util.current_command(process_type: str, *, data_dir: str | pathlib.Path, url: str | None = None)[source]
- archivebox.core.takeover_util.runtime_stack_owner(*, data_dir: str | pathlib.Path, exclude_id=None)[source]
Return the live local parent allowed to own the server runtime stack.
- archivebox.core.takeover_util.command_owns_runtime_stack(command, *, data_dir: str | pathlib.Path) bool[source]
- archivebox.core.takeover_util.foreground_runner_owner(*, data_dir: str | pathlib.Path, exclude_id=None)[source]
Return the newest live local parent allowed to borrow runner/sonic.
- archivebox.core.takeover_util.command_owns_foreground_runner(command, *, data_dir: str | pathlib.Path) bool[source]
- archivebox.core.takeover_util.live_runner_processes(*, data_dir: str | pathlib.Path)[source]
Return locally verifiable runners and warn about unsupported overlap.
A Process row from another machine is observability only: its PID cannot be checked or signalled here, so it neither joins the local election nor gets mutated. A row for this same Machine from another PID namespace represents a previous sequential container under the supported model; warn, retire the unreachable row, and let the new container continue.
- archivebox.core.takeover_util.enter_single_runner_gate(command, *, data_dir: str | pathlib.Path, graceful_timeout: float = 5.0) bool[source]
Admit one active runner for this Machine and DATA_DIR using Process rows.
The current process is a real OS process while it waits, so we keep its Process row RUNNING but mark worker_type=runner_waiting. Only the process that wins takeover is promoted to worker_type=worker_runner, which is protected by a partial unique DB constraint scoped to (Machine, DATA_DIR). Older locally verifiable runners are terminated and fully waited out before promotion, so runner work never overlaps on one machine. Foreign machines are intentionally outside this gate and only produce a warning above.