#!/bin/bash # Probes the OpenAI API every 10 min; once credits are back (HTTP 200) and the interim # post-processing is finished, relaunches the full SPID run (pending sections only). ROOT="$HOME/UQO_RESEARCH_DB"; cd "$ROOT/project-db" KEY=$(grep "^OPENAI_API_KEY=" .env | cut -d= -f2) while true; do code=$(curl -s -o /dev/null -w "%{http_code}" https://api.openai.com/v1/chat/completions -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" -d "{\"model\":\"gpt-4o-mini\",\"messages\":[{\"role\":\"user\",\"content\":\"ping\"}],\"max_tokens\":1}") echo "$(date "+%F %T") probe HTTP $code" >> "$ROOT/data/logs/spid_resume.log" if [ "$code" = "200" ] && [ -f "$ROOT/data/logs/stage.spid_interim.done" ]; then echo "$(date "+%F %T") credits back -> relaunching spid_run.sh" >> "$ROOT/data/logs/spid_resume.log" nohup "$ROOT/scripts/cluster/spid_run.sh" > "$ROOT/data/logs/nohup.spid.out" 2>&1 < /dev/null & exit 0 fi sleep 600 done