@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.
@@ -2650,7 +2650,10 @@ async function init(flow2, opts = {}) {
2650
2650
  context.isStop = () => stop;
2651
2651
  context = await setupModules(context, opts);
2652
2652
  const stopAfter = context.args.get("stopAfter");
2653
- const stopAllowance = context.params.get("stopAllowance", "number default 5");
2653
+ const stopAllowanceSec = Number(context.params.get("stopAllowance", "number default 60"));
2654
+ const stopAllowanceMs = (Number.isFinite(stopAllowanceSec) && stopAllowanceSec >= 0 ? stopAllowanceSec : 60) * 1e3;
2655
+ context.stopAllowanceSec = stopAllowanceSec;
2656
+ context.stopAllowanceMs = stopAllowanceMs;
2654
2657
  if (stopAfter === "init") {
2655
2658
  printAllParameters(context);
2656
2659
  process.exit(0);
@@ -2664,8 +2667,10 @@ async function init(flow2, opts = {}) {
2664
2667
  sigintCount = 1;
2665
2668
  firstSigintAt = now;
2666
2669
  stop = true;
2667
- context.logger.info(`>> emitting stop with allowance ${stopAllowance}`);
2668
- context.emitter.emit("stop", stopAllowance);
2670
+ context.logger.info(
2671
+ `>> emitting stop with allowance ${stopAllowanceSec}s (${stopAllowanceMs}ms)`
2672
+ );
2673
+ context.emitter.emit("stop", stopAllowanceMs);
2669
2674
  return;
2670
2675
  }
2671
2676
  if (now - firstSigintAt < 250) return;
@@ -2676,8 +2681,10 @@ async function init(flow2, opts = {}) {
2676
2681
  process.on("SIGTERM", () => {
2677
2682
  if (!context || stop) return;
2678
2683
  stop = true;
2679
- context.logger.info(`>> SIGTERM: emitting stop with allowance ${stopAllowance}`);
2680
- context.emitter.emit("stop", stopAllowance);
2684
+ context.logger.info(
2685
+ `>> SIGTERM: emitting stop with allowance ${stopAllowanceSec}s (${stopAllowanceMs}ms)`
2686
+ );
2687
+ context.emitter.emit("stop", stopAllowanceMs);
2681
2688
  });
2682
2689
  await flow2(context);
2683
2690
  } catch (error) {
@@ -2705,6 +2712,8 @@ async function init(flow2, opts = {}) {
2705
2712
  }
2706
2713
  if (process.exitCode && process.exitCode !== 0) {
2707
2714
  process.exit(process.exitCode);
2715
+ } else if (stop) {
2716
+ process.exit(0);
2708
2717
  }
2709
2718
  }
2710
2719
  }
@@ -6151,7 +6160,7 @@ var TaskStopRunner = class extends AbstractTask {
6151
6160
  */
6152
6161
  static async resolveCustomParams(context, overrides = {}) {
6153
6162
  const merged = AbstractTask._mergeTypedParams(context, "task-stop", {
6154
- allowanceMs: "number default 5000"
6163
+ allowanceMs: "number default 60000"
6155
6164
  }, overrides);
6156
6165
  const allowanceMs = Number(merged.allowanceMs);
6157
6166
  if (!Number.isFinite(allowanceMs) || allowanceMs < 0) {
@@ -6165,7 +6174,7 @@ var TaskStopRunner = class extends AbstractTask {
6165
6174
  * @returns {Promise<{ success: true, results: { stopRunner: true, allowanceMs: number, message: string } }>}
6166
6175
  */
6167
6176
  async run() {
6168
- const allowanceMs = Number(this.task?.params?.allowanceMs ?? 5e3);
6177
+ const allowanceMs = Number(this.task?.params?.allowanceMs ?? 6e4);
6169
6178
  this.context.logger.warn?.(`[TaskStopRunner] stop requested (allowanceMs=${allowanceMs})`);
6170
6179
  return {
6171
6180
  success: true,
@@ -6783,7 +6792,7 @@ async function executeClaimedTask(context, tasksTable, historyTable, row, regist
6783
6792
  await db(tasksTable).where({ id: row.id }).delete();
6784
6793
  }
6785
6794
  const stopRunnerRequested = !!(results && typeof results === "object" && results.stopRunner === true);
6786
- const stopAllowanceMs = stopRunnerRequested ? Number(results.allowanceMs ?? 5e3) : 0;
6795
+ const stopAllowanceMs = stopRunnerRequested ? Number(results.allowanceMs ?? 6e4) : 0;
6787
6796
  return { stopRunnerRequested, stopAllowanceMs };
6788
6797
  }
6789
6798
  function shuffleTaskRowsInPlace(rows) {
@@ -6873,7 +6882,7 @@ async function runTasksLoop(context, options) {
6873
6882
  const runningTaskInstances = /* @__PURE__ */ new Map();
6874
6883
  let runningControlPromise = null;
6875
6884
  let stopRequested = false;
6876
- let stopAllowanceMs = 5e3;
6885
+ let stopAllowanceMs = Number(context.stopAllowanceMs) > 0 ? Number(context.stopAllowanceMs) : 6e4;
6877
6886
  context.tasksRunnerStop = false;
6878
6887
  let registryReg = null;
6879
6888
  let registryInterval = null;
@@ -6940,7 +6949,7 @@ async function runTasksLoop(context, options) {
6940
6949
  ).then(async (outcome) => {
6941
6950
  if (outcome.stopRunnerRequested && !stopRequested) {
6942
6951
  stopRequested = true;
6943
- stopAllowanceMs = outcome.stopAllowanceMs || 5e3;
6952
+ stopAllowanceMs = outcome.stopAllowanceMs || stopAllowanceMs;
6944
6953
  context.tasksRunnerStop = true;
6945
6954
  await signalRunningTasksStop(context, runningTaskInstances, stopAllowanceMs);
6946
6955
  }
@@ -6966,7 +6975,7 @@ async function runTasksLoop(context, options) {
6966
6975
  const p = executeClaimedTask(context, tasksTable, historyTable, claimed, registry, runningTaskInstances).then(async (outcome) => {
6967
6976
  if (outcome.stopRunnerRequested && !stopRequested) {
6968
6977
  stopRequested = true;
6969
- stopAllowanceMs = outcome.stopAllowanceMs || 5e3;
6978
+ stopAllowanceMs = outcome.stopAllowanceMs || stopAllowanceMs;
6970
6979
  context.tasksRunnerStop = true;
6971
6980
  await signalRunningTasksStop(context, runningTaskInstances, stopAllowanceMs);
6972
6981
  }
@@ -6987,7 +6996,9 @@ async function runTasksLoop(context, options) {
6987
6996
  }
6988
6997
  }
6989
6998
  if (context.isStop() && !stopRequested) {
6990
- await signalRunningTasksStop(context, runningTaskInstances, 5e3);
6999
+ stopRequested = true;
7000
+ stopAllowanceMs = Number(context.stopAllowanceMs) > 0 ? Number(context.stopAllowanceMs) : stopAllowanceMs;
7001
+ await signalRunningTasksStop(context, runningTaskInstances, stopAllowanceMs);
6991
7002
  }
6992
7003
  if (runningPromises.size > 0) {
6993
7004
  if (stopRequested) {