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: object

A 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_path is the resolved form.

  • steps (list[StepSpec]) – The steps, in execution order.

  • 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

from_dict

Build a job from a decoded job document.

load

Read a job file.

resolve_path

Turn a path from the job file into an absolute path.

save

Write the job file and remember where it lives.

to_dict

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:
  • document (Mapping[str, Any]) – The decoded JSON object.

  • base_dir (str | Path | None) – Folder relative paths are resolved against. Defaults to the working directory.

  • source (str | Path | None) – The file the document came from.

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.

Parameters:

path (str | Path) – The job file.

Returns:

Job – The validated job.

Raises:

JobError – If the file cannot be read or is not a valid job.

to_dict() → dict[str, Any][source]#

Return the job as a JSON-serializable job document.

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 from base_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'
property output_path: Path#

The resolved output folder.

property result_path: Path | None#

Where the result file of this job is written by default.

<job file stem>.result.json next to the job file, or None for a job that was never read from or saved to a file.