Expand description
The schedr worker agent: process supervision, rendering, the runner channel.
The agent starts each task attempt as its own process, in its own process group, with a clean
environment; it captures the output, enforces the timeout and stops processes with SIGTERM then
SIGKILL (see archive/PROJECT.md, Worker environment and Master–worker protocol). The Python
runner talks to it over a Unix socket (channel).
Modules§
- agent
- The worker agent’s main loop: one control stream to the master, attempts and parse jobs, heartbeats and code watching (see archive/PROJECT.md, Worker lifecycle and Task assignment).
- api
- A task’s requests to schedr’s REST API (M4.11h, the user’s B2): sent to the master over the
agent’s stream, which runs them as the task; resent on a new stream until answered, for at
most
API_CALL_LIMIT. - attempt
- One attempt on the worker, from
AssignTasktoFinished: what to run and how it ended. - channel
- The agent’s end of the runner channel: length-prefixed JSON and the handshake.
- connection_
env - What a command gets of a connection (decisions 184, 190-192):
PREFIX_*variables, and the files its tools read (curl’s-Kconfig, an SSH key and config, Postgres’s.pgpass, a MySQL option file), written in the attempt’s folder. - connection_
jobs schedr connections checkandteston this worker (decisions 174, 193, 198-200): a check renders each connection through the worker’s secret storages, saying of every secret it names whether it is there (never a value); a test opens one connection in a runner and runs its check, as a one-off attempt beside the tasks (no slot), stopped after its timeout. One job at a time per worker.- ctx
- A command task’s context channel (decisions 143-146): the agent’s side of
schedr dag-ctxandschedr.script. - drain
- Draining the worker on shutdown (SIGTERM): what happens when, decided apart from the agent so it is tested with plain instants (see archive/PROJECT.md, Worker lifecycle: drain).
- env
- The environment of a task process: clean by default (see archive/PROJECT.md, Worker environment).
- fork
- The fork servers, agent side (see archive/PROJECT.md, How Python tasks are started: the fork
server): started with the worker, two per interpreter (one preloading the configured
libraries, a bare one), each restarted with backoff when it dies; a Python task or a parse
job asks the preloaded one to fork its runner, then the bare one, and is spawned when
neither can (a task with
preload=Falseasks only the bare one, one withfresh_process=Trueneither). - handles
- The cleanup handles an attempt registers: what its cleanup needs that only existed in the
attempt (see archive/PROJECT.md, Per-task cleanup). Masked as outputs are (decision 222), at
most
MAX_HANDLES_SIZEin all (decision 228). - jobs
schedr.toml: the scripts a script root declares (archive/PROJECT.md, Plain script delivery; decisions 292-300). Read and checked here, in Rust, by the agent alone (decision 293): every key known, unknown ones an error. A declaration with a schedule (schedule,everyoronce) is a standalone job, a one-task DAG whose ID is its reference (etl:team_a/schedr.toml#report_daily); one without is a script for DAGs only (296).- journal
- The journal on disk: one file per attempt the agent started and the master hasn’t acknowledged, so a restarted agent still reports a result it had and stops a task process its previous incarnation left behind (see archive/PROJECT.md, Worker lifecycle).
- launch
- Starting real processes for attempts and parse jobs: the runner with its end of a fresh socket pair, commands as they are, each supervised (timeout, cancel, SIGTERM then SIGKILL).
- logs
- The worker’s log endpoint (see archive/PROJECT.md, Task logs): the webserver reads task logs from the worker that ran them, a part at a time.
- mask
- Masking secret values in a task’s log and output (decision 167): each value the attempt
fetched, written
****. - master_
time - What a worker knows of master time (B225, B228): the leading master’s monotonic clock, on which every deadline the master and its workers must agree on is set.
- memory
- The memory watchdog (see archive/PROJECT.md, Worker memory protection and crash recovery): every task shares the pod’s memory, and the kernel’s out-of-memory killer would take every task and the agent with it, so the agent measures each task and kills only the one over its budget.
- metrics
- The worker agent’s metrics (see archive/PROJECT.md, Observability), registered in the process’s registry and served on the ops port. Each is updated where things happen; none costs anything at a scrape.
- output
- The captured stdout and stderr of a process: the last part up to the output size limit.
- parse
- Parse jobs on the worker: the runner in
parsemode over a root’s files, with a per-file timeout. - process
- The real task process: started in its own process group with a clean environment, its
stdout and stderr written to the task’s log file and kept (their tail) for the
ProcessResult. - render
- Rendering templates and command lines: references filled in from the run’s inputs and context, values written as text the same way the Python API writes literals.
- resource
- A command’s resource value (M4.8d): what a
CommandResourcesetup reports withschedr task-ctx resource set, and what a resource’scleanup_commandreads withresource get. - retention
- Log retention on the worker (see archive/PROJECT.md, Task logs): logs older than
[worker] log_retention(30 days by default) are deleted, and beyond[worker] log_max_size(no limit by default) the oldest go first. A log whose attempt is in the journal (running, or its result not yet acknowledged) is never deleted, though it counts towards the size limit. Parse logs (parse-<root>.log) follow the same rules. - scan
- Scanning a DAG root: the files it holds, and its content hash.
- secrets
- Secret storages on the worker, and the secrets of one attempt (see archive/PROJECT.md, Secret storage).
- status
- How an attempt ended: from the process’s termination and why the agent stopped it.
- supervise
- Supervising a task process: waiting for it, its timeout, cancellation, and stopping it with SIGTERM, then SIGKILL after the grace time (see archive/PROJECT.md, Master–worker protocol: cancellation).
- usage
- What a spawned process used, read from its zombie before it is reaped (decision 18A, see archive/PROJECT.md, How Python tasks are started: the fork server).
- vault
- The Vault secret storage (see archive/PROJECT.md, Secret storage): KV v2 reads of a mount, with a token from the environment or Vault’s Kubernetes auth (the pod’s service-account token). The agent’s own token is renewed before it expires; with Kubernetes auth, an expired or refused one is replaced by logging in again, once per read. Values that aren’t strings are read as their JSON text (decision 171).
- watch
- Change detection for DAG roots: polling, the settle time, and the content hash.
- watchers
- The watcher hosts: a worker’s wait steps, as coroutines in one long-lived process per code set (decision 320; see archive/PROJECT.md, Sensors and triggers).