#!/usr/bin/env bash
# A light detached watcher: enqueue scoring only when both C1 jobs succeed.
set -euo pipefail
cd "$(dirname "$0")/.."
deadline=$((SECONDS + 12 * 60 * 60))
while (( SECONDS < deadline )); do
    for name in 6500_c1_xfade_s0 6501_c1_xfade_s1; do
        if [[ -f "runners/jobs/failed/${name}.json" ]]; then
            printf 'C1 dependency failed: %s\n' "$name" >&2
            exit 1
        fi
    done
    if [[ -f runners/jobs/done/6500_c1_xfade_s0.json && -f runners/jobs/done/6501_c1_xfade_s1.json ]]; then
        exec ../../.venv/bin/python runners/jobqueue.py add 6600_c1_pstay_lodo -- \
            SCHEDULE_OFFSET=0 ../../.venv/bin/python -u score_c1_pstay.py
    fi
    sleep 60
done
printf 'Timed out waiting for C1 jobs\n' >&2
exit 1
