spb/uqo-research-db
Public
1#!/bin/bash2# Probes the OpenAI API every 10 min; once credits are back (HTTP 200) and the interim3# post-processing is finished, relaunches the full SPID run (pending sections only).4ROOT="$HOME/UQO_RESEARCH_DB"; cd "$ROOT/project-db"5KEY=$(grep "^OPENAI_API_KEY=" .env | cut -d= -f2)6while true; do7 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}")8 echo "$(date "+%F %T") probe HTTP $code" >> "$ROOT/data/logs/spid_resume.log"9 if [ "$code" = "200" ] && [ -f "$ROOT/data/logs/stage.spid_interim.done" ]; then10 echo "$(date "+%F %T") credits back -> relaunching spid_run.sh" >> "$ROOT/data/logs/spid_resume.log"11 nohup "$ROOT/scripts/cluster/spid_run.sh" > "$ROOT/data/logs/nohup.spid.out" 2>&1 < /dev/null &12 exit 013 fi14 sleep 60015done16