Python tool for aircraft Doppler audio geolocation using historical ADS-B flight data (Source-available)
Python acoustic-geolocationads-baircraft-trackingairplaneaudio-forensicsdoppler-effectdoppler-shiftgeolocationosintsignal-processing
feat(#10): add cancel and resume controls to CLI (#240)
Cinna Davis2f771ff23bee
diff --git a/README.md b/README.mdindex 4db28e4..99d9686 100644--- a/README.md+++ b/README.md@@ -52,6 +52,12 @@ Initial data acquisition can take hours and tens of gigabytes; [the workflow guiThe command prints a job ID when queued. In another terminal, run`.venv/bin/dopplergeist job JOB_ID --jobs jobs --watch` to follow reportedprogress, checkpoint rate, and the age of the latest tile and job status update.+Stop a running service-managed job with `.venv/bin/dopplergeist cancel JOB_ID`;+pass `--server-url` when the service uses a non-default port.+Resume a stopped job while its service remains active with+`.venv/bin/dopplergeist resume JOB_ID --server-url http://127.0.0.1:8765`, then+monitor it using `job JOB_ID --jobs jobs --watch`. If the service is stopped,+`resume JOB_ID --jobs jobs` resumes directly from the persistent job directory.### Discover events in a recordingdiff --git a/docs/PRODUCT.md b/docs/PRODUCT.mdindex 7d60d37..5883ba8 100644--- a/docs/PRODUCT.md+++ b/docs/PRODUCT.md@@ -55,7 +55,11 @@ dopplergeist analyze recording.mp3 --jobs jobs --online --max-runtime 14400 \--time-source 'Your evidence for this recording time'dopplergeist job JOB_ID --jobs jobsdopplergeist job JOB_ID --jobs jobs --watch --interval 10+dopplergeist cancel JOB_IDdopplergeist resume JOB_ID --jobs jobs+# If the upload service still owns the job store:+dopplergeist resume JOB_ID --server-url http://127.0.0.1:8765+dopplergeist job JOB_ID --jobs jobs --watch````analyze` prints the job ID and a monitor command to standard error as soon as@@ -66,6 +70,15 @@ job JSON to standard output. Pieces can have different sizes and costs, so theirrate is not an ETA; remotely staged work appears after it is imported. PressingCtrl-C stops the watcher without cancelling the analysis.+`cancel` sends the cancellation request to the local service at+`http://127.0.0.1:8765`. If `serve` uses a different port, pass its base URL with+`--server-url`. The service must be running and managing the job directory.+When `serve` owns the job-store lock, use the same `--server-url` option with+`resume`; it prints the queued result after the service accepts the request.+Monitor it with `job --watch` and the service's `--jobs` directory. Without+`--server-url`, `resume --jobs` runs directly against a job store and requires+that no service currently owns its lock.+The UTC window bounds the recording start, not the event occurrence or upload.Missing time is a required-input result. Scores are ranking statistics, notprobabilities. Sensitivity radii must not be described as calibrated confidence.diff --git a/src/dopplergeist/cli.py b/src/dopplergeist/cli.pyindex 18f2a5d..d0418b0 100644--- a/src/dopplergeist/cli.py+++ b/src/dopplergeist/cli.py@@ -6,6 +6,8 @@ import sysimport timefrom importlib.metadata import PackageNotFoundError, versionfrom pathlib import Path+from urllib.error import HTTPError, URLError+from urllib.request import Request, urlopenimport uuid@@ -35,6 +37,26 @@ def job_identifier(value):return value+def post_job_action(server_url, job_id, action, parser):+ url=server_url.rstrip("/")+f"/api/jobs/{job_id}/{action}"+ request=Request(url,data=b"",method="POST")+ try:+ with urlopen(request,timeout=10) as response:+ body=response.read()+ except HTTPError as exc:+ try:+ detail=json.loads(exc.read()).get("error",str(exc))+ except (AttributeError,ValueError):+ detail=str(exc)+ parser.error(f"Could not {action} job {job_id}: HTTP {exc.code}: {detail}")+ except (URLError,ValueError) as exc:+ parser.error(f"Could not reach job service at {server_url}: {exc}")+ try:+ return json.loads(body)+ except ValueError as exc:+ parser.error(f"Job service returned invalid JSON when requesting {action} for {job_id}: {exc}")++def main():parser=argparse.ArgumentParser(description="Aircraft acoustic geolocation research pipeline")try:@@ -73,9 +95,14 @@ def main():job.add_argument("--jobs",default="jobs")job.add_argument("--watch",action="store_true",help="Watch local checkpoints until the job stops")job.add_argument("--interval",type=positive_runtime,default=10,help="Watch interval in seconds")+ cancel=sub.add_parser("cancel",help="Cancel a job managed by the local upload service")+ cancel.add_argument("job_id",type=job_identifier)+ cancel.add_argument("--server-url",default="http://127.0.0.1:8765",+ help="Base URL of the service managing this job")resume=sub.add_parser("resume",help="Resume a stopped job after completed audio discovery")resume.add_argument("job_id",type=job_identifier)resume.add_argument("--jobs",default="jobs")+ resume.add_argument("--server-url",help="Base URL of the service managing this job")resume.add_argument("--max-runtime",type=positive_runtime,default=3600)args=parser.parse_args()if args.command in {"analyze", "serve"}:@@ -156,7 +183,14 @@ def main():print("Stopped watching; the job continues.",file=sys.stderr)raise SystemExit(130)print(json.dumps(value,indent=2))+ elif args.command=="cancel":+ value=post_job_action(args.server_url,args.job_id,"cancel",parser)+ print(json.dumps(value,indent=2))elif args.command=="resume":+ if args.server_url:+ value=post_job_action(args.server_url,args.job_id,"resume",parser)+ print(json.dumps(value,indent=2))+ returnfrom .jobs import JobManagertry:manager=JobManager(args.jobs,max_runtime_s=args.max_runtime)