@nmakarov/cli-toolkit 0.51.0 → 0.55.0

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.
@@ -2634,7 +2634,10 @@ async function init(flow2, opts = {}) {
2634
2634
  context.isStop = () => stop;
2635
2635
  context = await setupModules(context, opts);
2636
2636
  const stopAfter = context.args.get("stopAfter");
2637
- const stopAllowance = context.params.get("stopAllowance", "number default 5");
2637
+ const stopAllowanceSec = Number(context.params.get("stopAllowance", "number default 60"));
2638
+ const stopAllowanceMs = (Number.isFinite(stopAllowanceSec) && stopAllowanceSec >= 0 ? stopAllowanceSec : 60) * 1e3;
2639
+ context.stopAllowanceSec = stopAllowanceSec;
2640
+ context.stopAllowanceMs = stopAllowanceMs;
2638
2641
  if (stopAfter === "init") {
2639
2642
  printAllParameters(context);
2640
2643
  process.exit(0);
@@ -2648,8 +2651,10 @@ async function init(flow2, opts = {}) {
2648
2651
  sigintCount = 1;
2649
2652
  firstSigintAt = now;
2650
2653
  stop = true;
2651
- context.logger.info(`>> emitting stop with allowance ${stopAllowance}`);
2652
- context.emitter.emit("stop", stopAllowance);
2654
+ context.logger.info(
2655
+ `>> emitting stop with allowance ${stopAllowanceSec}s (${stopAllowanceMs}ms)`
2656
+ );
2657
+ context.emitter.emit("stop", stopAllowanceMs);
2653
2658
  return;
2654
2659
  }
2655
2660
  if (now - firstSigintAt < 250) return;
@@ -2660,8 +2665,10 @@ async function init(flow2, opts = {}) {
2660
2665
  process.on("SIGTERM", () => {
2661
2666
  if (!context || stop) return;
2662
2667
  stop = true;
2663
- context.logger.info(`>> SIGTERM: emitting stop with allowance ${stopAllowance}`);
2664
- context.emitter.emit("stop", stopAllowance);
2668
+ context.logger.info(
2669
+ `>> SIGTERM: emitting stop with allowance ${stopAllowanceSec}s (${stopAllowanceMs}ms)`
2670
+ );
2671
+ context.emitter.emit("stop", stopAllowanceMs);
2665
2672
  });
2666
2673
  await flow2(context);
2667
2674
  } catch (error) {
@@ -2689,6 +2696,8 @@ async function init(flow2, opts = {}) {
2689
2696
  }
2690
2697
  if (process.exitCode && process.exitCode !== 0) {
2691
2698
  process.exit(process.exitCode);
2699
+ } else if (stop) {
2700
+ process.exit(0);
2692
2701
  }
2693
2702
  }
2694
2703
  }
@@ -6135,7 +6144,7 @@ var TaskStopRunner = class extends AbstractTask {
6135
6144
  */
6136
6145
  static async resolveCustomParams(context, overrides = {}) {
6137
6146
  const merged = AbstractTask._mergeTypedParams(context, "task-stop", {
6138
- allowanceMs: "number default 5000"
6147
+ allowanceMs: "number default 60000"
6139
6148
  }, overrides);
6140
6149
  const allowanceMs = Number(merged.allowanceMs);
6141
6150
  if (!Number.isFinite(allowanceMs) || allowanceMs < 0) {
@@ -6149,7 +6158,7 @@ var TaskStopRunner = class extends AbstractTask {
6149
6158
  * @returns {Promise<{ success: true, results: { stopRunner: true, allowanceMs: number, message: string } }>}
6150
6159
  */
6151
6160
  async run() {
6152
- const allowanceMs = Number(this.task?.params?.allowanceMs ?? 5e3);
6161
+ const allowanceMs = Number(this.task?.params?.allowanceMs ?? 6e4);
6153
6162
  this.context.logger.warn?.(`[TaskStopRunner] stop requested (allowanceMs=${allowanceMs})`);
6154
6163
  return {
6155
6164
  success: true,
@@ -6767,7 +6776,7 @@ async function executeClaimedTask(context, tasksTable, historyTable, row, regist
6767
6776
  await db(tasksTable).where({ id: row.id }).delete();
6768
6777
  }
6769
6778
  const stopRunnerRequested = !!(results && typeof results === "object" && results.stopRunner === true);
6770
- const stopAllowanceMs = stopRunnerRequested ? Number(results.allowanceMs ?? 5e3) : 0;
6779
+ const stopAllowanceMs = stopRunnerRequested ? Number(results.allowanceMs ?? 6e4) : 0;
6771
6780
  return { stopRunnerRequested, stopAllowanceMs };
6772
6781
  }
6773
6782
  function shuffleTaskRowsInPlace(rows) {
@@ -6857,7 +6866,7 @@ async function runTasksLoop(context, options) {
6857
6866
  const runningTaskInstances = /* @__PURE__ */ new Map();
6858
6867
  let runningControlPromise = null;
6859
6868
  let stopRequested = false;
6860
- let stopAllowanceMs = 5e3;
6869
+ let stopAllowanceMs = Number(context.stopAllowanceMs) > 0 ? Number(context.stopAllowanceMs) : 6e4;
6861
6870
  context.tasksRunnerStop = false;
6862
6871
  let registryReg = null;
6863
6872
  let registryInterval = null;
@@ -6924,7 +6933,7 @@ async function runTasksLoop(context, options) {
6924
6933
  ).then(async (outcome) => {
6925
6934
  if (outcome.stopRunnerRequested && !stopRequested) {
6926
6935
  stopRequested = true;
6927
- stopAllowanceMs = outcome.stopAllowanceMs || 5e3;
6936
+ stopAllowanceMs = outcome.stopAllowanceMs || stopAllowanceMs;
6928
6937
  context.tasksRunnerStop = true;
6929
6938
  await signalRunningTasksStop(context, runningTaskInstances, stopAllowanceMs);
6930
6939
  }
@@ -6950,7 +6959,7 @@ async function runTasksLoop(context, options) {
6950
6959
  const p = executeClaimedTask(context, tasksTable, historyTable, claimed, registry, runningTaskInstances).then(async (outcome) => {
6951
6960
  if (outcome.stopRunnerRequested && !stopRequested) {
6952
6961
  stopRequested = true;
6953
- stopAllowanceMs = outcome.stopAllowanceMs || 5e3;
6962
+ stopAllowanceMs = outcome.stopAllowanceMs || stopAllowanceMs;
6954
6963
  context.tasksRunnerStop = true;
6955
6964
  await signalRunningTasksStop(context, runningTaskInstances, stopAllowanceMs);
6956
6965
  }
@@ -6971,7 +6980,9 @@ async function runTasksLoop(context, options) {
6971
6980
  }
6972
6981
  }
6973
6982
  if (context.isStop() && !stopRequested) {
6974
- await signalRunningTasksStop(context, runningTaskInstances, 5e3);
6983
+ stopRequested = true;
6984
+ stopAllowanceMs = Number(context.stopAllowanceMs) > 0 ? Number(context.stopAllowanceMs) : stopAllowanceMs;
6985
+ await signalRunningTasksStop(context, runningTaskInstances, stopAllowanceMs);
6975
6986
  }
6976
6987
  if (runningPromises.size > 0) {
6977
6988
  if (stopRequested) {