Adiciona script bootstrap para rodar ranking + componente B automaticamente
This commit is contained in:
66
backend/scripts/bootstrap_ranking.sh
Normal file
66
backend/scripts/bootstrap_ranking.sh
Normal file
@@ -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 - <<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 - <<PY
|
||||||
|
import cx_Oracle
|
||||||
|
conn=cx_Oracle.connect("local123","local123","${DSN_HOST}")
|
||||||
|
cur=conn.cursor();cur.execute("select count(*) from tb_ranking_consultor")
|
||||||
|
print(cur.fetchone()[0])
|
||||||
|
cur.close();conn.close()
|
||||||
|
PY
|
||||||
|
)
|
||||||
|
echo " Registros na TB_RANKING_CONSULTOR: ${COUNT}"
|
||||||
|
|
||||||
|
if [ "${COUNT}" -eq 0 ]; then
|
||||||
|
echo "[3/5] Rodando job de ranking (A/C/D)..."
|
||||||
|
curl -s -X POST "${API_URL}/api/v1/ranking/processar?limpar=false" >/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 - <<PY
|
||||||
|
import cx_Oracle
|
||||||
|
conn=cx_Oracle.connect("local123","local123","${DSN_HOST}")
|
||||||
|
cur=conn.cursor()
|
||||||
|
cur.execute("select count(*) from tb_ranking_consultor"); print("total",cur.fetchone()[0])
|
||||||
|
cur.execute("select count(*) from tb_ranking_consultor where componente_b>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."
|
||||||
Reference in New Issue
Block a user