| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- import fs from "node:fs";
- import path from "node:path";
- import { execSync } from "node:child_process";
- import { fileURLToPath } from "node:url";
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
- const LOGS_DIR = path.resolve(__dirname, "logs");
- function logMaisRecente() {
- const candidatos = fs.readdirSync(LOGS_DIR)
- .filter((f) => f.startsWith("reavaliar-temperature-zero-") && f.endsWith(".log"))
- .map((f) => ({ f, mtime: fs.statSync(path.join(LOGS_DIR, f)).mtimeMs }))
- .sort((a, b) => b.mtime - a.mtime);
- return candidatos[0]?.f ?? null;
- }
- function processoRodando() {
- try {
- const out = execSync("ps aux | grep reavaliarComTemperatureZero | grep -v grep", { encoding: "utf8" });
- return out.trim().length > 0;
- } catch {
- return false;
- }
- }
- function barraProgresso(pct, largura = 30) {
- const preenchido = Math.round((pct / 100) * largura);
- return "█".repeat(preenchido) + "░".repeat(largura - preenchido);
- }
- function main() {
- const arquivo = logMaisRecente();
- if (!arquivo) {
- console.log("Nenhum log de reavaliar-temperature-zero encontrado em scripts/logs/.");
- return;
- }
- const conteudo = fs.readFileSync(path.join(LOGS_DIR, arquivo), "utf8");
- const linhas = conteudo.trim().split("\n");
- const concluido = linhas.find((l) => l.includes("[reavaliar-temp0] concluído"));
- const falha = linhas.find((l) => l.includes("falha fatal"));
- const progressoLinhas = linhas.filter((l) => l.includes("[reavaliar-temp0] progresso:"));
- const ultimaJanela = [...linhas].reverse().find((l) => l.includes("janela"));
- console.log(`Log: ${arquivo}`);
- console.log(`Processo rodando agora: ${processoRodando() ? "sim" : "não"}`);
- if (falha) {
- console.log(`\n⚠ FALHA FATAL: ${falha}`);
- return;
- }
- if (concluido) {
- console.log(`\n✔ ${concluido}`);
- return;
- }
- if (!progressoLinhas.length) {
- console.log("\nAinda sem nenhuma linha de progresso (ou está fora da janela, aguardando reabrir).");
- if (ultimaJanela) console.log(ultimaJanela);
- return;
- }
- const ultima = progressoLinhas[progressoLinhas.length - 1];
- const m = /progresso: (\d+)\/(\d+) \| erros: (\d+) \| (\d+)min decorridos \| ~(\d+)min restantes/.exec(ultima);
- if (!m) {
- console.log("\nNão consegui parsear a última linha de progresso:", ultima);
- return;
- }
- const [, processados, total, erros, decorridos, restantes] = m.map(Number);
- const pct = Math.round((processados / total) * 100);
- console.log(`\n${barraProgresso(pct)} ${pct}%`);
- console.log(`${processados}/${total} atendimentos | erros: ${erros}`);
- console.log(`${decorridos}min decorridos | ~${restantes}min restantes (~${Math.round(restantes / 60)}h)`);
- if (ultimaJanela && ultimaJanela !== ultima) console.log(`\n${ultimaJanela}`);
- }
- main();
|