diff --git a/backend/scripts/bootstrap_ranking.sh b/backend/scripts/bootstrap_ranking.sh new file mode 100644 index 0000000..7ad394b --- /dev/null +++ b/backend/scripts/bootstrap_ranking.sh @@ -0,0 +1,66 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Configs +DSN_HOST=${ORACLE_LOCAL_DSN:-"127.0.0.1:1521/XEPDB1"} +API_URL=${API_URL:-"http://localhost:8000"} +VENV_PY="./venv/bin/python" + +echo "[1/5] Aguardando Oracle em ${DSN_HOST}..." +until $VENV_PY - </dev/null 2>&1 +import cx_Oracle +conn=cx_Oracle.connect("local123","local123","${DSN_HOST}") +cur=conn.cursor();cur.execute("select 1 from dual");cur.fetchone() +cur.close();conn.close() +PY +do + echo " Oracle ainda indisponível... tentando de novo em 5s" + sleep 5 +done +echo "Oracle OK." + +echo "[2/5] Conferindo contagem atual..." +COUNT=$($VENV_PY - </dev/null + # Espera concluir + while true; do + STATUS=$(curl -s "${API_URL}/api/v1/ranking/status") + running=$(python - <<'PY' +import os, json +data=json.loads(os.environ["STATUS"]) +print(data.get("running", False)) +PY +STATUS="$STATUS") + echo " Status: ${STATUS}" + if [ "$running" != "True" ] && [ "$running" != "true" ]; then + break + fi + sleep 20 + done +fi + +echo "[4/5] Rodando Componente B (PPG)..." +ORACLE_LOCAL_DSN=${DSN_HOST} PYTHONUNBUFFERED=1 $VENV_PY scripts/popular_componente_b.py + +echo "[5/5] Contagens finais:" +$VENV_PY - <0"); print("B>0",cur.fetchone()[0]) +cur.execute("select max(pontuacao_total) from tb_ranking_consultor"); print("max total",cur.fetchone()[0]) +cur.close();conn.close() +PY +echo "Pronto."