@danhachuel/thunderbolt 0.5.65 → 0.5.66

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/scripts/cli.mjs +23 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danhachuel/thunderbolt",
3
- "version": "0.5.65",
3
+ "version": "0.5.66",
4
4
  "description": "Thunderbolt — interface local para operação de canais faceless e motor MoneyPrinterTurbo",
5
5
  "license": "MIT",
6
6
  "main": "scripts/cli.mjs",
package/scripts/cli.mjs CHANGED
@@ -67,6 +67,21 @@ function configuredMoneyPrinterPath() {
67
67
  }
68
68
  }
69
69
 
70
+ function readStateJson(filename, fallback = []) {
71
+ try { return JSON.parse(readFileSync(join(thunderboltHome, "storage", "state", filename), "utf8")); }
72
+ catch { return fallback; }
73
+ }
74
+
75
+ function hasScheduledAutomation() {
76
+ const channels = readStateJson("channels.json", []);
77
+ return Array.isArray(channels) && channels.some((channel) => channel && channel.automation_on === true);
78
+ }
79
+
80
+ function hasPendingPipelineWork() {
81
+ const tasks = readStateJson("tasks.json", []);
82
+ return Array.isArray(tasks) && tasks.some((task) => ["queued", "pending", "processing", "running", "in_progress"].includes(String(task?.state || task?.status || "").toLowerCase()));
83
+ }
84
+
70
85
  function ensureRuntimeStorage() {
71
86
  const storageRoot = process.env.THUNDERBOLT_STORAGE_DIR || join(thunderboltHome, "storage");
72
87
  const directories = [
@@ -261,18 +276,18 @@ proxy.on("error", (error) => {
261
276
  proxy.listen(publicPort, "127.0.0.1", () => {
262
277
  console.log(`Thunderbolt: interface disponível em http://localhost:${publicPort}/`);
263
278
  });
264
- const worker = spawn(python, ["-m", "hermes_ui.automation_worker"], {
279
+ const worker = hasScheduledAutomation() ? spawn(python, ["-m", "hermes_ui.automation_worker"], {
265
280
  cwd: root,
266
281
  stdio: "inherit",
267
282
  env: runtimeEnv,
268
283
  windowsHide: false,
269
- });
270
- const pipelineWorker = spawn(python, ["-m", "hermes_ui.pipeline_worker"], {
284
+ }) : null;
285
+ const pipelineWorker = hasPendingPipelineWork() ? spawn(python, ["-m", "hermes_ui.pipeline_worker"], {
271
286
  cwd: root,
272
287
  stdio: "inherit",
273
288
  env: runtimeEnv,
274
289
  windowsHide: false,
275
- });
290
+ }) : null;
276
291
  const restartExitCode = 75;
277
292
  let shuttingDown = false;
278
293
  let child;
@@ -315,10 +330,10 @@ startStreamlit();
315
330
  const stopWorker = () => {
316
331
  shuttingDown = true;
317
332
  proxy.close();
318
- if (!worker.killed) worker.kill();
319
- if (!pipelineWorker.killed) pipelineWorker.kill();
333
+ if (worker && !worker.killed) worker.kill();
334
+ if (pipelineWorker && !pipelineWorker.killed) pipelineWorker.kill();
320
335
  };
321
336
  process.on("SIGINT", stopWorker);
322
337
  process.on("SIGTERM", stopWorker);
323
- worker.on("error", (error) => console.error(`Thunderbolt worker: ${error.message}`));
324
- pipelineWorker.on("error", (error) => console.error(`Thunderbolt pipeline worker: ${error.message}`));
338
+ worker?.on("error", (error) => console.error(`Thunderbolt worker: ${error.message}`));
339
+ pipelineWorker?.on("error", (error) => console.error(`Thunderbolt pipeline worker: ${error.message}`));