Remove referencias ao Componente B dos scripts de inicializacao

This commit is contained in:
Frederico Castro
2025-12-13 16:50:11 -03:00
parent 2d4e93f82a
commit 93fb0d8a39
2 changed files with 10 additions and 32 deletions

View File

@@ -1,7 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail set -euo pipefail
# Escolhe binário do Python (funciona no host ou dentro do container)
if [ -x "./venv/bin/python" ]; then if [ -x "./venv/bin/python" ]; then
VENV_PY="./venv/bin/python" VENV_PY="./venv/bin/python"
elif command -v python3 >/dev/null 2>&1; then elif command -v python3 >/dev/null 2>&1; then
@@ -10,7 +9,6 @@ else
VENV_PY="python" VENV_PY="python"
fi fi
# Configs
DSN_CANDIDATES=() DSN_CANDIDATES=()
if [ -n "${ORACLE_LOCAL_DSN:-}" ]; then if [ -n "${ORACLE_LOCAL_DSN:-}" ]; then
DSN_CANDIDATES+=("${ORACLE_LOCAL_DSN}") DSN_CANDIDATES+=("${ORACLE_LOCAL_DSN}")
@@ -18,7 +16,7 @@ fi
DSN_CANDIDATES+=("127.0.0.1:1521/XEPDB1" "oracle18c:1521/XEPDB1" "mqapilc_oracle18c:1521/XEPDB1") DSN_CANDIDATES+=("127.0.0.1:1521/XEPDB1" "oracle18c:1521/XEPDB1" "mqapilc_oracle18c:1521/XEPDB1")
API_URL=${API_URL:-"http://localhost:8000"} API_URL=${API_URL:-"http://localhost:8000"}
echo "[1/5] Aguardando Oracle..." echo "[1/4] Aguardando Oracle..."
DSN_HOST="" DSN_HOST=""
for candidate in "${DSN_CANDIDATES[@]}"; do for candidate in "${DSN_CANDIDATES[@]}"; do
echo " Testando ${candidate}..." echo " Testando ${candidate}..."
@@ -36,13 +34,13 @@ PY
done done
if [ -z "$DSN_HOST" ]; then if [ -z "$DSN_HOST" ]; then
echo "ERRO: não foi possível conectar ao Oracle em nenhum dos DSN candidatos." echo "ERRO: nao foi possivel conectar ao Oracle em nenhum dos DSN candidatos."
exit 1 exit 1
fi fi
echo "Oracle OK em ${DSN_HOST}." echo "Oracle OK em ${DSN_HOST}."
echo "[2/5] Conferindo contagem atual..." echo "[2/4] Conferindo contagem atual..."
COUNT=$($VENV_PY - <<PY COUNT=$($VENV_PY - <<PY
import cx_Oracle import cx_Oracle
conn=cx_Oracle.connect("local123","local123","${DSN_HOST}") conn=cx_Oracle.connect("local123","local123","${DSN_HOST}")
@@ -52,19 +50,10 @@ cur.close();conn.close()
PY PY
) )
echo " Registros na TB_RANKING_CONSULTOR: ${COUNT}" 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 if [ "${COUNT}" -eq 0 ]; then
echo "[3/5] Rodando job de ranking (A/C/D)..." echo "[3/4] Rodando job de ranking (Blocos A/C/D)..."
curl -s -X POST "${API_URL}/api/v1/ranking/processar?limpar=false" >/dev/null curl -s -X POST "${API_URL}/api/v1/ranking/processar?limpar=false" >/dev/null
# Espera concluir
while true; do while true; do
STATUS=$(curl -s "${API_URL}/api/v1/ranking/status") STATUS=$(curl -s "${API_URL}/api/v1/ranking/status")
running=$($VENV_PY - <<'PY' running=$($VENV_PY - <<'PY'
@@ -79,30 +68,19 @@ STATUS="$STATUS")
fi fi
sleep 20 sleep 20
done 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 else
echo "[3/5] Tabela já possui dados e componente B preenchido (max=${MAX_B}). Pulando cálculo pesado." echo "[3/4] Tabela ja possui dados. Pulando processamento."
NEED_B="no"
fi fi
if [ "${NEED_B}" = "yes" ]; then echo "[4/4] Contagens finais:"
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 $VENV_PY - <<PY
import cx_Oracle import cx_Oracle
conn=cx_Oracle.connect("local123","local123","${DSN_HOST}") conn=cx_Oracle.connect("local123","local123","${DSN_HOST}")
cur=conn.cursor() cur=conn.cursor()
cur.execute("select count(*) from tb_ranking_consultor"); print("total",cur.fetchone()[0]) 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 count(*) from tb_ranking_consultor where componente_a>0"); print("Bloco A>0",cur.fetchone()[0])
cur.execute("select max(componente_b) from tb_ranking_consultor"); print("max B",cur.fetchone()[0]) cur.execute("select count(*) from tb_ranking_consultor where componente_c>0"); print("Bloco C>0",cur.fetchone()[0])
cur.execute("select count(*) from tb_ranking_consultor where componente_d>0"); print("Bloco D>0",cur.fetchone()[0])
cur.execute("select max(pontuacao_total) from tb_ranking_consultor"); print("max total",cur.fetchone()[0]) cur.execute("select max(pontuacao_total) from tb_ranking_consultor"); print("max total",cur.fetchone()[0])
cur.close();conn.close() cur.close();conn.close()
PY PY

View File

@@ -33,7 +33,7 @@ if ! docker ps | grep -q ranking_frontend; then
exit 1 exit 1
fi fi
echo "[4b/5] Rodando bootstrap (ranking + componente B) dentro do backend..." echo "[4b/5] Rodando bootstrap do ranking dentro do backend..."
docker exec ranking_backend bash -lc "ORACLE_LOCAL_DSN=oracle18c:1521/XEPDB1 /app/scripts/bootstrap_ranking.sh" docker exec ranking_backend bash -lc "ORACLE_LOCAL_DSN=oracle18c:1521/XEPDB1 /app/scripts/bootstrap_ranking.sh"
echo "[5/5] Iniciando ngrok..." echo "[5/5] Iniciando ngrok..."