Ajusta bootstrap e portas para subida sem conflitos
This commit is contained in:
36
backend/scripts/bootstrap_ranking.sh
Normal file → Executable file
36
backend/scripts/bootstrap_ranking.sh
Normal file → Executable file
@@ -1,6 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Escolhe binário do Python (funciona no host ou dentro do container)
|
||||
if [ -x "./venv/bin/python" ]; then
|
||||
VENV_PY="./venv/bin/python"
|
||||
elif command -v python3 >/dev/null 2>&1; then
|
||||
VENV_PY="python3"
|
||||
else
|
||||
VENV_PY="python"
|
||||
fi
|
||||
|
||||
# Configs
|
||||
DSN_CANDIDATES=()
|
||||
if [ -n "${ORACLE_LOCAL_DSN:-}" ]; then
|
||||
@@ -8,7 +17,6 @@ if [ -n "${ORACLE_LOCAL_DSN:-}" ]; then
|
||||
fi
|
||||
DSN_CANDIDATES+=("127.0.0.1:1521/XEPDB1" "oracle18c:1521/XEPDB1" "mqapilc_oracle18c:1521/XEPDB1")
|
||||
API_URL=${API_URL:-"http://localhost:8000"}
|
||||
VENV_PY="./venv/bin/python"
|
||||
|
||||
echo "[1/5] Aguardando Oracle..."
|
||||
DSN_HOST=""
|
||||
@@ -44,6 +52,14 @@ cur.close();conn.close()
|
||||
PY
|
||||
)
|
||||
echo " Registros na TB_RANKING_CONSULTOR: ${COUNT}"
|
||||
MAX_B=$($VENV_PY - <<PY
|
||||
import cx_Oracle
|
||||
conn=cx_Oracle.connect("local123","local123","${DSN_HOST}")
|
||||
cur=conn.cursor();cur.execute("select nvl(max(componente_b),0) from tb_ranking_consultor")
|
||||
print(cur.fetchone()[0])
|
||||
cur.close();conn.close()
|
||||
PY
|
||||
)
|
||||
|
||||
if [ "${COUNT}" -eq 0 ]; then
|
||||
echo "[3/5] Rodando job de ranking (A/C/D)..."
|
||||
@@ -51,7 +67,7 @@ if [ "${COUNT}" -eq 0 ]; then
|
||||
# Espera concluir
|
||||
while true; do
|
||||
STATUS=$(curl -s "${API_URL}/api/v1/ranking/status")
|
||||
running=$(python - <<'PY'
|
||||
running=$($VENV_PY - <<'PY'
|
||||
import os, json
|
||||
data=json.loads(os.environ["STATUS"])
|
||||
print(data.get("running", False))
|
||||
@@ -63,10 +79,21 @@ STATUS="$STATUS")
|
||||
fi
|
||||
sleep 20
|
||||
done
|
||||
NEED_B="yes"
|
||||
elif [ "${MAX_B}" -eq 0 ]; then
|
||||
echo "[3/5] Tabela já tem dados, mas componente B nunca foi preenchido (max=0)."
|
||||
NEED_B="yes"
|
||||
else
|
||||
echo "[3/5] Tabela já possui dados e componente B preenchido (max=${MAX_B}). Pulando cálculo pesado."
|
||||
NEED_B="no"
|
||||
fi
|
||||
|
||||
echo "[4/5] Rodando Componente B (PPG)..."
|
||||
ORACLE_LOCAL_DSN=${DSN_HOST} PYTHONUNBUFFERED=1 $VENV_PY scripts/popular_componente_b.py
|
||||
if [ "${NEED_B}" = "yes" ]; then
|
||||
echo "[4/5] Rodando Componente B (PPG)..."
|
||||
ORACLE_LOCAL_DSN=${DSN_HOST} PYTHONUNBUFFERED=1 $VENV_PY scripts/popular_componente_b.py
|
||||
else
|
||||
echo "[4/5] Componente B já presente, sem necessidade de recálculo."
|
||||
fi
|
||||
|
||||
echo "[5/5] Contagens finais:"
|
||||
$VENV_PY - <<PY
|
||||
@@ -75,6 +102,7 @@ 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(componente_b) from tb_ranking_consultor"); print("max B",cur.fetchone()[0])
|
||||
cur.execute("select max(pontuacao_total) from tb_ranking_consultor"); print("max total",cur.fetchone()[0])
|
||||
cur.close();conn.close()
|
||||
PY
|
||||
|
||||
Reference in New Issue
Block a user