Job#
- class rapidtools.jobs.Job(output_dir: str, steps: list[~rapidtools.jobs.schema.StepSpec], id: str = '', name: str = '', created_at: str = '', created_by: dict[str, ~typing.Any] = <factory>, metadata: dict[str, ~typing.Any] = <factory>, schema_version: str = '1.0', base_dir: ~pathlib.Path = <factory>, source: ~pathlib.Path | None = None)[source]#
Bases:
objectA job: where to write, and the steps to run in order.
- Variables:
output_dir (str) – Folder every step writes into, as given in the file.
output_pathis the resolved form.id (str) – Identifier of the job; generated when omitted.
name (str) – Human-readable name shown in logs and results.
created_at (str) – UTC creation time (ISO 8601).
created_by (dict[str, Any]) – Who wrote the file, e.g.
{'client': 'rapidtools-gui', 'version': '0.3.0'}.metadata (dict[str, Any]) – Free-form notes; never interpreted.
schema_version (str) – Interface version the file declares.
base_dir (Path) – Folder relative paths are resolved against: the folder of the job file, or the working directory for a job built in memory.
source (Path | None) – The file the job was read from or saved to.
Example
>>> job = Job(output_dir='out', steps=[StepSpec( ... id='detect', type='detect.aerial', ... inputs={'raster': 'scene.tiff'}, params={'assets': ['tree']})]) >>> job.to_dict()['schema'], len(job.steps) ('rapidtools.job', 1)
Methods
Build a job from a decoded job document.
Read a job file.
Turn a path from the job file into an absolute path.
Write the job file and remember where it lives.
Return the job as a JSON-serializable job document.
- classmethod from_dict(document: Mapping[str, Any], base_dir: str | Path | None = None, source: str | Path | None = None) Job[source]#
Build a job from a decoded job document.
- Parameters:
- Returns:
Job – The validated job.
- Raises:
JobError – If the document does not follow the job schema.
- classmethod load(path: str | Path) Job[source]#
Read a job file.
Relative paths inside the file are resolved against its folder.
- save(path: str | Path) Path[source]#
Write the job file and remember where it lives.
- Parameters:
path (str | Path) – Destination file.
- Returns:
Path – The absolute path written.
- resolve_path(raw: str | Path) Path[source]#
Turn a path from the job file into an absolute path.
~is expanded and a relative path is taken frombase_dir. Symbolic links are left alone.Example
>>> job = Job(output_dir='out', base_dir='/data/run7', steps=[ ... StepSpec(id='s1', type='detect.aerial')]) >>> str(job.resolve_path('scene.tiff')) '/data/run7/scene.tiff'