schedr.runner.watchers¶
The watcher host: every wait step of one code set, as coroutines in one process.
A long-lived runner (decision 320), multiplexed by watcher ID over the agent’s socket. A wait step spends its life waiting, so one process and one slot-free coroutine each is cheap where a process per step isn’t. Its DAG file is imported once per host, on the loop: imports behave as in a task, and its top level isn’t run again for each attempt.
The agent’s socket is read by a thread of its own, so a watcher waiting for an answer (a secret, a connection) can be answered while the loop is held; the answers go to who asked. Watchers share the process: its working directory and environment are the host’s, never a run’s.
What a watcher runs with asyncio.to_thread belongs to it: its log and secrets, and its time
(decision 337). A call cancelled, or still running when its watcher ends, has
StepEndedError raised in its thread, the one way Python has to reach one; a thread that doesn’t
end within the cancel grace (blocked in C, or ignoring it) can only end with its process.
- class schedr.runner.watchers.WatcherChannel(host, watcher)¶
Bases:
objectWhat one watcher sees of the channel: its own messages, its own answers.
- Parameters:
host (_Host)
watcher (int)
- grace¶
the host’s cancel grace.
- Type:
How long a call it stops has to end
- send(message)¶
Sends one message of this watcher.
- Parameters:
message (dict[str, Any]) – A JSON object with a
type.- Return type:
None
- ask(message)¶
Sends a request and waits for its answer, holding what called it.
That is the loop for a call from a coroutine, as
task_ctx.secretis: other watchers wait for as long as the agent takes to answer.- Parameters:
message (dict[str, Any]) – The request.
- Returns:
The answer.
- Return type:
dict[str, Any]
- schedr.runner.watchers.guarded_loop_factory()¶
The host’s event loop:
uvloopstarts processes where the audit hook can’t see them.- Returns:
Its factory;
Noneforasyncio’s own, which the hook sees.- Return type:
Callable[[], asyncio.AbstractEventLoop] | None
- schedr.runner.watchers.run_watchers(channel, request)¶
Handles a
watchersrequest: serves watchers until the agent stops the host.- Parameters:
channel (Channel) – The channel to the agent.
request (dict[str, Any]) – The
watchersmessage (thesys.pathentries of its code set).
- Returns:
The exit code; it ends when the agent closes the channel, or is killed.
- Return type:
int