| 123456789101112131415161718192021222324 |
- #!/usr/bin/env bash
- set -euo pipefail
- # Single detached remote job runner. It records a minimal, atomic status.
- run_root="${PROD2U_RUN_ROOT:-/data/prod2u/runs}"
- job_id="${1:-$(date -u +%Y%m%dT%H%M%SZ)-$$}"
- shift || true
- job_dir="$run_root/$job_id"
- mkdir -p "$job_dir"
- printf '{"schema":"prod2u-remote-job-v1","run_id":"%s","status":"RUNNING"}\n' "$job_id" >"$job_dir/RUN-STATUS.json.tmp"
- mv "$job_dir/RUN-STATUS.json.tmp" "$job_dir/RUN-STATUS.json"
- if (($# == 0)); then
- printf '{"schema":"prod2u-remote-job-v1","run_id":"%s","status":"PASS","exit_code":0}\n' "$job_id" >"$job_dir/RESULT.json.tmp"
- mv "$job_dir/RESULT.json.tmp" "$job_dir/RESULT.json"
- exit 0
- fi
- set +e
- "$@" >"$job_dir/stdout.log" 2>"$job_dir/stderr.log"
- rc=$?
- set -e
- status=PASS; if ((rc != 0)); then status=FAIL; fi
- printf '{"schema":"prod2u-remote-job-v1","run_id":"%s","status":"%s","exit_code":%d}\n' "$job_id" "$status" "$rc" >"$job_dir/RESULT.json.tmp"
- mv "$job_dir/RESULT.json.tmp" "$job_dir/RESULT.json"
- printf '%d\n' "$rc" >"$job_dir/exit-code"
- exit "$rc"
|