OCDocker.Workbench.Jobs module¶
Local subprocess launcher and tracker for Workbench API jobs (vs,
pipeline, ocscore_train, ocscore_reduce). Job state is persisted
under <served root>/.ocdocker-jobs/ so status survives an API restart.
Local subprocess launcher and tracker for Workbench API jobs.
- exception OCDocker.Workbench.Jobs.JobError(message, *, status_code=400)[source]¶
Bases:
ExceptionHTTP-aware error raised by Workbench job execution helpers.
- Parameters:
message (str)
status_code (int)
- Return type:
None
- class OCDocker.Workbench.Jobs.JobManager(root, *, executable='ocdocker')[source]¶
Bases:
objectLaunch and track
ocdockerCLI jobs as local subprocesses.- Parameters:
root (str | Path)
executable (str)
- __init__(root, *, executable='ocdocker')[source]¶
Bind a job manager to one served Workbench root.
- Parameters:
root (str or pathlib.Path) – Served Workbench root. Job artifacts are written under
root / ".ocdocker-jobs".executable (str) –
ocdockerexecutable used to launch jobs.
- Return type:
None
- plan(kind, args, *, cwd=None, manifest=None, engine='shell', cores=4, results_dir=None)[source]¶
Compute the command a job would run, without launching it.
- Parameters:
kind (WorkbenchJobKind) – Job kind. Selects the
ocdockersubcommand prefix, or (for"vs_campaign") the execution engine building the batch command.args (Sequence[str]) – Extra command-line arguments appended after the subcommand prefix (or, for
"vs_campaign", appended to every row).cwd (str, pathlib.Path, or None) – Working directory the job would run in. Defaults to the served root.
manifest (Sequence[dict[str, Any]] or None) – Required for
kind="vs_campaign": one entry per sample (sample,receptor,ligand,box,engines, optionalrescoring_engines). Ignored for other kinds.engine (str) –
"shell"(default, a generated POSIX loop) or"snakemake"(the bundled multi-sample Snakefile, real DAG orchestration). Only meaningful forkind="vs_campaign".cores (int) –
--corespassed to Snakemake. Only meaningful forengine="snakemake".results_dir (str or None) – Shared base output directory; each row writes to
<results_dir>/<sample>. Only meaningful forkind="vs_campaign".
- Returns:
JSON-safe preview:
kind,command,cwd.- Return type:
dict[str, Any]
- Raises:
JobError – If
kind/engineis unsupported,cwddoes not exist, or (for"vs_campaign")manifestis missing or malformed.
- launch(kind, args, *, cwd=None, manifest=None, engine='shell', cores=4, results_dir=None)[source]¶
Launch one tracked job as a background subprocess.
- Parameters:
kind (WorkbenchJobKind) – Job kind. Selects the
ocdockersubcommand prefix, or (for"vs_campaign") the execution engine building the batch command.args (Sequence[str]) – Extra command-line arguments appended after the subcommand prefix (or, for
"vs_campaign", appended to every row).cwd (str, pathlib.Path, or None) – Working directory for the launched process. Defaults to the served root.
manifest (Sequence[dict[str, Any]] or None) – Required for
kind="vs_campaign": seeplan().engine (str) –
"shell"or"snakemake": seeplan().cores (int) –
--corespassed to Snakemake: seeplan().results_dir (str or None) – Shared base output directory: see
plan().
- Returns:
Tracked job record with
status: "running".- Return type:
WorkbenchJobRecord
- Raises:
JobError – If
kind/engineis unsupported,cwddoes not exist,manifestis missing/malformed for"vs_campaign", or the subprocess could not be launched.
- list()[source]¶
Return every tracked job, most recently created first.
- Returns:
Tracked job records with freshly reconciled status.
- Return type:
tuple[WorkbenchJobRecord, …]
- logs(job_id, *, lines=80, max_bytes=65536)[source]¶
Return bounded stdout and stderr previews for one tracked job.
- Parameters:
job_id (str) – Job identifier returned by
launch().lines (int) – Maximum returned lines per log file.
max_bytes (int) – Maximum bytes read from the end of each log file.
- Returns:
Stdout preview, then stderr preview.
- Return type:
tuple[RunLogFilePreview, RunLogFilePreview]
- Raises:
JobError – If no job with
job_idis tracked.
- OCDocker.Workbench.Jobs.build_campaign_script(manifest, args, *, executable='ocdocker', results_dir=None)[source]¶
Build a POSIX shell script that runs one
ocdockercommand per manifest row.Shared by
JobManager.launch()/JobManager.plan()(to actually build/preview a"vs_campaign"job’s command) andOCDocker.Workbench.VSDesign.plan_vs_campaign()(to preview the same script before a job is ever created) — one source of truth for what a campaign script looks like.- Parameters:
manifest (Sequence[dict[str, Any]] or None) – One entry per sample:
sample,row_kind("vs"or"pipeline"),receptor,ligand,box,engines(non-empty), optionalrescoring_engines.args (Sequence[str]) – Flags appended to every row’s command (common to the whole batch).
executable (str) –
ocdockerexecutable invoked for each row.results_dir (str or None) – Every row gets its own
--outdir <results_dir>/<sample>— a shared literal--outdirinargswould make every row overwrite the same directory, sinceocdocker vs/pipelinewrite straight under--outdirwith no per-sample nesting of their own. Defaults toDEFAULT_CAMPAIGN_RESULTS_DIRwhen omitted, matching the bundled Snakefile’s default so bothvs_campaignengines isolate samples the same way.
- Returns:
Generated shell script. Continues past a failing row; exits non-zero only if any row failed.
- Return type:
str
- Raises:
JobError – If
manifestis empty or a row is missing a required field.
- OCDocker.Workbench.Jobs.build_campaign_snakemake_command(manifest, args, *, executable='ocdocker', cores=4, results_dir=None)[source]¶
Build the
snakemakeargv for a vs_campaign job using the bundled multi-sample Snakefile.Shared by
JobManager.launch()/JobManager.plan()(to actually build/preview a"vs_campaign",engine="snakemake"job’s command) andOCDocker.Workbench.VSDesign.plan_vs_campaign()(to preview the same command before a job is ever created). Unlikebuild_campaign_script(), real Snakemake DAG orchestration handles parallelism (--cores) and continuing past a failing sample (--keep-going) itself — this only builds the invocation.- Parameters:
manifest (Sequence[dict[str, Any]] or None) – One entry per sample:
sample,row_kind("vs"or"pipeline"),receptor,ligand,box,engines(non-empty), optionalrescoring_engines.args (Sequence[str]) – Flags appended to every row’s command (common to the whole batch), passed to the Snakefile as its
common_argsconfig value.executable (str) –
ocdockerexecutable invoked for each row (Snakefileocdocker_commandconfig value).cores (int) –
--corespassed to Snakemake.results_dir (str or None) – Shared base output directory (Snakefile
results_dirconfig value, default"results"); each sample’s output and.campaign_donemarker land under<results_dir>/<sample>.
- Returns:
snakemakeargv, ready forJobManager._spawn().- Return type:
tuple[str, …]
- Raises:
JobError – If
manifestis empty or a row is missing a required field.