@danhachuel/thunderbolt 0.5.73 → 0.5.74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scripts/cli.mjs +29 -5
package/package.json
CHANGED
package/scripts/cli.mjs
CHANGED
|
@@ -276,14 +276,37 @@ proxy.on("error", (error) => {
|
|
|
276
276
|
proxy.listen(publicPort, "127.0.0.1", () => {
|
|
277
277
|
console.log(`Thunderbolt: interface disponível em http://localhost:${publicPort}/`);
|
|
278
278
|
});
|
|
279
|
-
//
|
|
280
|
-
//
|
|
281
|
-
//
|
|
282
|
-
|
|
279
|
+
// A worker de automação é necessária para canais com automação activa. É
|
|
280
|
+
// iniciada no máximo uma vez por launcher e reiniciada com backoff se terminar
|
|
281
|
+
// inesperadamente; não é criada quando não há trabalho agendado.
|
|
282
|
+
let worker = null;
|
|
283
283
|
const pipelineWorker = null;
|
|
284
284
|
const restartExitCode = 75;
|
|
285
285
|
let shuttingDown = false;
|
|
286
286
|
let child;
|
|
287
|
+
let workerRestartTimer = null;
|
|
288
|
+
|
|
289
|
+
function startAutomationWorker() {
|
|
290
|
+
if (shuttingDown || worker || !hasScheduledAutomation()) return;
|
|
291
|
+
worker = spawn(python, ["-m", "hermes_ui.automation_worker"], {
|
|
292
|
+
cwd: root,
|
|
293
|
+
stdio: "inherit",
|
|
294
|
+
env: runtimeEnv,
|
|
295
|
+
windowsHide: false,
|
|
296
|
+
});
|
|
297
|
+
worker.on("error", (error) => console.error(`Thunderbolt worker: ${error.message}`));
|
|
298
|
+
worker.on("exit", (code, signal) => {
|
|
299
|
+
worker = null;
|
|
300
|
+
if (shuttingDown) return;
|
|
301
|
+
console.error(`Thunderbolt worker: terminou (código ${code ?? "-"}, sinal ${signal ?? "-"}).`);
|
|
302
|
+
if (hasScheduledAutomation()) {
|
|
303
|
+
workerRestartTimer = setTimeout(() => {
|
|
304
|
+
workerRestartTimer = null;
|
|
305
|
+
startAutomationWorker();
|
|
306
|
+
}, 5000);
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
}
|
|
287
310
|
|
|
288
311
|
function startStreamlit() {
|
|
289
312
|
child = spawn(python, [streamlitBootstrap, "run", main, "--server.port", String(backendPort), "--server.address", "127.0.0.1"], {
|
|
@@ -323,10 +346,11 @@ startStreamlit();
|
|
|
323
346
|
const stopWorker = () => {
|
|
324
347
|
shuttingDown = true;
|
|
325
348
|
proxy.close();
|
|
349
|
+
if (workerRestartTimer) clearTimeout(workerRestartTimer);
|
|
326
350
|
if (worker && !worker.killed) worker.kill();
|
|
327
351
|
if (pipelineWorker && !pipelineWorker.killed) pipelineWorker.kill();
|
|
328
352
|
};
|
|
329
353
|
process.on("SIGINT", stopWorker);
|
|
330
354
|
process.on("SIGTERM", stopWorker);
|
|
331
|
-
worker?.on("error", (error) => console.error(`Thunderbolt worker: ${error.message}`));
|
|
332
355
|
pipelineWorker?.on("error", (error) => console.error(`Thunderbolt pipeline worker: ${error.message}`));
|
|
356
|
+
startAutomationWorker();
|