@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.
@@ -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) {
@@ -6135,7 +6142,7 @@ var TaskStopRunner = class extends AbstractTask {
6135
6142
  */
6136
6143
  static async resolveCustomParams(context, overrides = {}) {
6137
6144
  const merged = AbstractTask._mergeTypedParams(context, "task-stop", {
6138
- allowanceMs: "number default 5000"
6145
+ allowanceMs: "number default 60000"
6139
6146
  }, overrides);
6140
6147
  const allowanceMs = Number(merged.allowanceMs);
6141
6148
  if (!Number.isFinite(allowanceMs) || allowanceMs < 0) {
@@ -6149,7 +6156,7 @@ var TaskStopRunner = class extends AbstractTask {
6149
6156
  * @returns {Promise<{ success: true, results: { stopRunner: true, allowanceMs: number, message: string } }>}
6150
6157
  */
6151
6158
  async run() {
6152
- const allowanceMs = Number(this.task?.params?.allowanceMs ?? 5e3);
6159
+ const allowanceMs = Number(this.task?.params?.allowanceMs ?? 6e4);
6153
6160
  this.context.logger.warn?.(`[TaskStopRunner] stop requested (allowanceMs=${allowanceMs})`);
6154
6161
  return {
6155
6162
  success: true,
@@ -6767,7 +6774,7 @@ async function executeClaimedTask(context, tasksTable, historyTable, row, regist
6767
6774
  await db(tasksTable).where({ id: row.id }).delete();
6768
6775
  }
6769
6776
  const stopRunnerRequested = !!(results && typeof results === "object" && results.stopRunner === true);
6770
- const stopAllowanceMs = stopRunnerRequested ? Number(results.allowanceMs ?? 5e3) : 0;
6777
+ const stopAllowanceMs = stopRunnerRequested ? Number(results.allowanceMs ?? 6e4) : 0;
6771
6778
  return { stopRunnerRequested, stopAllowanceMs };
6772
6779
  }
6773
6780
  function shuffleTaskRowsInPlace(rows) {
@@ -6857,7 +6864,7 @@ async function runTasksLoop(context, options) {
6857
6864
  const runningTaskInstances = /* @__PURE__ */ new Map();
6858
6865
  let runningControlPromise = null;
6859
6866
  let stopRequested = false;
6860
- let stopAllowanceMs = 5e3;
6867
+ let stopAllowanceMs = Number(context.stopAllowanceMs) > 0 ? Number(context.stopAllowanceMs) : 6e4;
6861
6868
  context.tasksRunnerStop = false;
6862
6869
  let registryReg = null;
6863
6870
  let registryInterval = null;
@@ -6924,7 +6931,7 @@ async function runTasksLoop(context, options) {
6924
6931
  ).then(async (outcome) => {
6925
6932
  if (outcome.stopRunnerRequested && !stopRequested) {
6926
6933
  stopRequested = true;
6927
- stopAllowanceMs = outcome.stopAllowanceMs || 5e3;
6934
+ stopAllowanceMs = outcome.stopAllowanceMs || stopAllowanceMs;
6928
6935
  context.tasksRunnerStop = true;
6929
6936
  await signalRunningTasksStop(context, runningTaskInstances, stopAllowanceMs);
6930
6937
  }
@@ -6950,7 +6957,7 @@ async function runTasksLoop(context, options) {
6950
6957
  const p = executeClaimedTask(context, tasksTable, historyTable, claimed, registry, runningTaskInstances).then(async (outcome) => {
6951
6958
  if (outcome.stopRunnerRequested && !stopRequested) {
6952
6959
  stopRequested = true;
6953
- stopAllowanceMs = outcome.stopAllowanceMs || 5e3;
6960
+ stopAllowanceMs = outcome.stopAllowanceMs || stopAllowanceMs;
6954
6961
  context.tasksRunnerStop = true;
6955
6962
  await signalRunningTasksStop(context, runningTaskInstances, stopAllowanceMs);
6956
6963
  }
@@ -6971,7 +6978,9 @@ async function runTasksLoop(context, options) {
6971
6978
  }
6972
6979
  }
6973
6980
  if (context.isStop() && !stopRequested) {
6974
- await signalRunningTasksStop(context, runningTaskInstances, 5e3);
6981
+ stopRequested = true;
6982
+ stopAllowanceMs = Number(context.stopAllowanceMs) > 0 ? Number(context.stopAllowanceMs) : stopAllowanceMs;
6983
+ await signalRunningTasksStop(context, runningTaskInstances, stopAllowanceMs);
6975
6984
  }
6976
6985
  if (runningPromises.size > 0) {
6977
6986
  if (stopRequested) {