@nmakarov/cli-toolkit 0.50.0 → 0.53.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) {
@@ -6151,7 +6158,7 @@ var TaskStopRunner = class extends AbstractTask {
6151
6158
  */
6152
6159
  static async resolveCustomParams(context, overrides = {}) {
6153
6160
  const merged = AbstractTask._mergeTypedParams(context, "task-stop", {
6154
- allowanceMs: "number default 5000"
6161
+ allowanceMs: "number default 60000"
6155
6162
  }, overrides);
6156
6163
  const allowanceMs = Number(merged.allowanceMs);
6157
6164
  if (!Number.isFinite(allowanceMs) || allowanceMs < 0) {
@@ -6165,7 +6172,7 @@ var TaskStopRunner = class extends AbstractTask {
6165
6172
  * @returns {Promise<{ success: true, results: { stopRunner: true, allowanceMs: number, message: string } }>}
6166
6173
  */
6167
6174
  async run() {
6168
- const allowanceMs = Number(this.task?.params?.allowanceMs ?? 5e3);
6175
+ const allowanceMs = Number(this.task?.params?.allowanceMs ?? 6e4);
6169
6176
  this.context.logger.warn?.(`[TaskStopRunner] stop requested (allowanceMs=${allowanceMs})`);
6170
6177
  return {
6171
6178
  success: true,
@@ -6783,7 +6790,7 @@ async function executeClaimedTask(context, tasksTable, historyTable, row, regist
6783
6790
  await db(tasksTable).where({ id: row.id }).delete();
6784
6791
  }
6785
6792
  const stopRunnerRequested = !!(results && typeof results === "object" && results.stopRunner === true);
6786
- const stopAllowanceMs = stopRunnerRequested ? Number(results.allowanceMs ?? 5e3) : 0;
6793
+ const stopAllowanceMs = stopRunnerRequested ? Number(results.allowanceMs ?? 6e4) : 0;
6787
6794
  return { stopRunnerRequested, stopAllowanceMs };
6788
6795
  }
6789
6796
  function shuffleTaskRowsInPlace(rows) {
@@ -6873,7 +6880,7 @@ async function runTasksLoop(context, options) {
6873
6880
  const runningTaskInstances = /* @__PURE__ */ new Map();
6874
6881
  let runningControlPromise = null;
6875
6882
  let stopRequested = false;
6876
- let stopAllowanceMs = 5e3;
6883
+ let stopAllowanceMs = Number(context.stopAllowanceMs) > 0 ? Number(context.stopAllowanceMs) : 6e4;
6877
6884
  context.tasksRunnerStop = false;
6878
6885
  let registryReg = null;
6879
6886
  let registryInterval = null;
@@ -6940,7 +6947,7 @@ async function runTasksLoop(context, options) {
6940
6947
  ).then(async (outcome) => {
6941
6948
  if (outcome.stopRunnerRequested && !stopRequested) {
6942
6949
  stopRequested = true;
6943
- stopAllowanceMs = outcome.stopAllowanceMs || 5e3;
6950
+ stopAllowanceMs = outcome.stopAllowanceMs || stopAllowanceMs;
6944
6951
  context.tasksRunnerStop = true;
6945
6952
  await signalRunningTasksStop(context, runningTaskInstances, stopAllowanceMs);
6946
6953
  }
@@ -6966,7 +6973,7 @@ async function runTasksLoop(context, options) {
6966
6973
  const p = executeClaimedTask(context, tasksTable, historyTable, claimed, registry, runningTaskInstances).then(async (outcome) => {
6967
6974
  if (outcome.stopRunnerRequested && !stopRequested) {
6968
6975
  stopRequested = true;
6969
- stopAllowanceMs = outcome.stopAllowanceMs || 5e3;
6976
+ stopAllowanceMs = outcome.stopAllowanceMs || stopAllowanceMs;
6970
6977
  context.tasksRunnerStop = true;
6971
6978
  await signalRunningTasksStop(context, runningTaskInstances, stopAllowanceMs);
6972
6979
  }
@@ -6987,7 +6994,9 @@ async function runTasksLoop(context, options) {
6987
6994
  }
6988
6995
  }
6989
6996
  if (context.isStop() && !stopRequested) {
6990
- await signalRunningTasksStop(context, runningTaskInstances, 5e3);
6997
+ stopRequested = true;
6998
+ stopAllowanceMs = Number(context.stopAllowanceMs) > 0 ? Number(context.stopAllowanceMs) : stopAllowanceMs;
6999
+ await signalRunningTasksStop(context, runningTaskInstances, stopAllowanceMs);
6991
7000
  }
6992
7001
  if (runningPromises.size > 0) {
6993
7002
  if (stopRequested) {