plesty.server.services.jobs
Runs commands as jobs: a detached process whose record and log a JobStore keeps.
The store (plesty.server.model.job) knows nothing about processes; this
service supplies the two facts it lacks — whether a pid is alive and what
exit code the launcher left — and the launch itself. An install, an update, a
field test or plesty check in a device’s environment all go through
JobRunner.start(); what differs is only the command line and the
kind on the record.
Classes
Start, observe and cancel jobs under a |
Module Contents
- class plesty.server.services.jobs.JobRunner(home: plesty.server.model.home.Home, store: plesty.server.model.job.JobStore | None = None)
Start, observe and cancel jobs under a
Home.Bind to a home.
- Parameters:
home (plesty.server.model.home.Home) – The bench home.
store (plesty.server.model.job.JobStore | None) – The record store; a fresh one on home by default.
- home
- store
- exit_file(job_id: str) pathlib.Path
Where the launcher records the exit code of job_id.
- Parameters:
job_id (str)
- Return type:
pathlib.Path
- start(name: str, kind: str, command: list[str], cwd: str | os.PathLike[str], env: collections.abc.Mapping[str, str] | None = None, detail: collections.abc.Mapping[str, Any] | None = None) plesty.server.model.job.Job
Launch command as a job and return its record.
- Parameters:
name (str) – Device instance the job belongs to.
kind (str) – Job kind, part of the id.
command (list[str]) – The command line.
cwd (str | os.PathLike[str]) – Working directory.
env (collections.abc.Mapping[str, str] | None) – Environment on top of the bench’s own.
detail (collections.abc.Mapping[str, Any] | None) – Kind-specific data stored on the record.
- Raises:
JobError – When the command cannot be launched.
- Return type:
- get(job_id: str) plesty.server.model.job.Job | None
The job job_id with its state brought up to date, or
None.- Parameters:
job_id (str)
- Return type:
plesty.server.model.job.Job | None
- require(job_id: str) plesty.server.model.job.Job
Like
get()but raisesJobErrorwhen unknown.- Parameters:
job_id (str)
- Return type:
- list(name: str | None = None, kind: str | None = None) list[plesty.server.model.job.Job]
Jobs on record, newest first, brought up to date.
- Parameters:
name (str | None)
kind (str | None)
- Return type:
- wait(job_id: str, timeout: float | None = None, poll: float = 0.25) plesty.server.model.job.Job
Block until the job finishes (or timeout seconds pass); returns it.
- Parameters:
job_id (str)
timeout (float | None)
poll (float)
- Return type:
- cancel(job_id: str) bool
Kill a running job (its whole process tree);
Truewhen it was running.- Parameters:
job_id (str)
- Return type:
bool