JobRunner#

class rapidtools.jobs.JobRunner(workflow: Any = None, progress: Callable[[str], None] | None = None)[source]#

Bases: object

Executes jobs with a workflow engine.

Parameters:
  • workflow (Any) – The engine that does the work, an AssetAnalysisWorkflow. A long-lived client such as the GUI passes its own, so that cancellation and cached models are shared between jobs. When omitted, a workflow is created on first use and its progress messages are copied into the result file.

  • progress (Callable[[str], None] | None) – Receives each progress message of a workflow created by the runner.

Example

>>> runner = JobRunner()
>>> runner.validate({
...     'schema': 'rapidtools.job', 'schema_version': '1.0',
...     'output_dir': 'out',
...     'steps': [{'type': 'detect.aerial',
...                'inputs': {'raster': 'scene.tiff'},
...                'params': {'assets': ['building']}}],
... })

Methods

cancel

Ask the job to stop.

run

Run a job and return its result.

validate

Check every step of a job without running anything.

property workflow: Any#

The workflow engine, created on first use when none was given.

cancel() → None[source]#

Ask the job to stop.

The running step stops at its next safe point (the current batch or tile finishes first) and no further step is started.

validate(job: Job | Mapping[str, Any] | str | Path, secrets: Secrets | Mapping[str, str] | str | Path | None = None, allow_missing_secrets: bool = False) → Job[source]#

Check every step of a job without running anything.

Parameters:
  • job (Job | Mapping[str, Any] | str | Path) – The job, a decoded job document, or the path of a job file.

  • secrets (Secrets | Mapping[str, str] | str | Path | None) – Secret values, or the path of a secrets file.

  • allow_missing_secrets (bool) – Accept secret references that cannot be resolved here (the machine that runs the job will have them). Defaults to False.

Returns:

Job – The validated job.

Raises:

JobError – If the job or any of its steps is invalid.

run(job: Job | Mapping[str, Any] | str | Path, secrets: Secrets | Mapping[str, str] | str | Path | None = None, result_path: str | Path | None = None, on_step: Callable[[StepResult], None] | None = None) → JobResult[source]#

Run a job and return its result.

Every step is validated before the first one starts. Steps then run in order; the first failure or cancellation ends the job and marks the remaining steps skipped. A failing step does not raise: the outcome is in the returned result (and its file), and JobResult.raise_for_status() re-raises the original exception for callers that prefer one.

Parameters:
  • job (Job | Mapping[str, Any] | str | Path) – The job, a decoded job document, or the path of a job file.

  • secrets (Secrets | Mapping[str, str] | str | Path | None) – Secret values, or the path of a secrets file.

  • result_path (str | Path | None) – Where to write the result file. Defaults to <job file stem>.result.json next to the job file; a job that is not on disk gets no result file.

  • on_step (Callable[[StepResult], None] | None) – Called after each step that ran (whatever its status), before the next one starts. An exception raised by it fails the job.

Returns:

JobResult – The outcome.

Raises:

JobError – Only if the job itself cannot be read (missing file, not JSON, not a job document).