Skip to content

Python tool for aircraft Doppler audio geolocation using historical ADS-B flight data (Source-available)

Return nonzero status for failed CLI jobs (#358)

Cinna Davis88e53299a8df
diff --git a/docs/PRODUCT.md b/docs/PRODUCT.md
index 737d40b..4285df3 100644
--- a/docs/PRODUCT.md
+++ b/docs/PRODUCT.md
@@ -95,6 +95,13 @@ or retention evidence, and the file-count rate is not a completed-work rate or
ETA. Remotely staged work appears after it is imported. Pressing Ctrl-C stops
the watcher without cancelling the analysis.
+Direct `analyze` and `resume --jobs` print the terminal result as JSON and exit
+with status 1 for a failed job or 130 for cancellation. They exit 0 for
+`succeeded`, `needs_input`, or `inconclusive`: a zero exit status means the
+command completed, not that a location was established. Automation must inspect
+the JSON `status`. A server-side resume only requests that the job be queued;
+check the job result separately.
+
Direct `analyze` accepts up to 100 MiB by default. Set `--max-upload-mb 250`,
for example, to allow a larger local recording. The `serve` command has its own
`--max-upload-mb` setting for uploads through the local web interface.
diff --git a/src/dopplergeist/cli.py b/src/dopplergeist/cli.py
index b458b0b..d4bec93 100644
--- a/src/dopplergeist/cli.py
+++ b/src/dopplergeist/cli.py
@@ -77,6 +77,14 @@ def post_job_action(server_url, job_id, action, parser):
parser.error(f"Job service returned invalid JSON when requesting {action} for {job_id}: {exc}")
+def print_terminal_result(result):
+ print(json.dumps(result, indent=2))
+ if result.get("status") == "failed":
+ raise SystemExit(1)
+ if result.get("status") == "cancelled":
+ raise SystemExit(130)
+
+
def main():
parser=argparse.ArgumentParser(description="Aircraft acoustic geolocation research pipeline")
try:
@@ -197,7 +205,7 @@ def main():
parser.error(f"Could not submit recording: {exc}")
print(f"Job {queued['job_id']} started. Monitor: dopplergeist job {queued['job_id']} "
f"--jobs {shlex.quote(str(args.jobs))} --watch",file=sys.stderr,flush=True)
- print(json.dumps(manager.wait(queued["job_id"]),indent=2))
+ print_terminal_result(manager.wait(queued["job_id"]))
finally:
manager.close()
elif args.command=="job":
@@ -298,7 +306,7 @@ def main():
parser.error(f"Could not open job store: {exc}")
try:
manager.resume(args.job_id)
- print(json.dumps(manager.wait(args.job_id),indent=2))
+ print_terminal_result(manager.wait(args.job_id))
except (KeyError, OSError, OverflowError, ValueError) as exc:
parser.error(f"Could not resume job {args.job_id}: {exc}")
finally:
diff --git a/tests/test_cli_input_errors.py b/tests/test_cli_input_errors.py
index f040826..ccad708 100644
--- a/tests/test_cli_input_errors.py
+++ b/tests/test_cli_input_errors.py
@@ -38,6 +38,16 @@ def test_analyze_reports_job_store_initialization_error_without_traceback():
assert "Traceback" not in run.stderr
+def test_analyze_exits_nonzero_for_failed_job(tmp_path):
+ # The invalid configuration fails before audio intake; only a real path is needed.
+ config = tmp_path / "operator.json"
+ config.write_text('{"search_workers": 0}')
+ run = _run_cli("analyze", Path(__file__), "--jobs", tmp_path / "jobs", "--config", config)
+
+ assert run.returncode == 1
+ assert '"status": "failed"' in run.stdout
+
+
def test_serve_reports_job_store_initialization_error_without_traceback():
existing_file = Path(__file__)
run = _run_cli("serve", "--jobs", existing_file, "--port", "0")