@nmakarov/cli-toolkit 0.70.0 → 0.71.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.
package/dist/tasks.cjs CHANGED
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  var tasks_exports = {};
31
31
  __export(tasks_exports, {
32
32
  AbstractTask: () => AbstractTask,
33
+ DEFAULT_RUNTIME_PARAM_SPECS: () => DEFAULT_RUNTIME_PARAM_SPECS,
33
34
  LOGGER_RUNTIME_KEYS: () => LOGGER_RUNTIME_KEYS,
34
35
  LOOP_RUNTIME_KEYS: () => LOOP_RUNTIME_KEYS,
35
36
  SERVICE_TASK_NAMES: () => SERVICE_TASK_NAMES,
@@ -64,6 +65,7 @@ __export(tasks_exports, {
64
65
  listServicesRegistry: () => listServicesRegistry,
65
66
  matchesParsedPattern: () => matchesParsedPattern,
66
67
  mergeAllowedTasksWithServiceTasks: () => mergeAllowedTasksWithServiceTasks,
68
+ mergeRuntimeParamSpecs: () => mergeRuntimeParamSpecs,
67
69
  nextTimeMatch: () => nextTimeMatch,
68
70
  normalizeAllowedTasks: () => normalizeAllowedTasks,
69
71
  queueToTableNames: () => queueToTableNames,
@@ -77,6 +79,8 @@ __export(tasks_exports, {
77
79
  resolveSteps: () => resolveSteps,
78
80
  runNodeTaskScript: () => runNodeTaskScript,
79
81
  runTasksLoop: () => runTasksLoop,
82
+ runtimeParamSpecsFromMetadata: () => runtimeParamSpecsFromMetadata,
83
+ runtimeValuesForSpecs: () => runtimeValuesForSpecs,
80
84
  taskHistoryInsertFromQueueRow: () => taskHistoryInsertFromQueueRow,
81
85
  timeMatcher: () => timeMatcher,
82
86
  touchRunnerHeartbeat: () => touchServicesRegistry,
@@ -2789,6 +2793,67 @@ var LOGGER_RUNTIME_KEYS = [
2789
2793
  "progressWithTimes",
2790
2794
  "progressThrottleMs"
2791
2795
  ];
2796
+ var DEFAULT_RUNTIME_PARAM_SPECS = [
2797
+ {
2798
+ key: "maxParallel",
2799
+ type: "number",
2800
+ label: "Max parallel",
2801
+ description: "Worker-lane concurrency (how many tasks claim at once)"
2802
+ },
2803
+ {
2804
+ key: "pollMs",
2805
+ type: "number",
2806
+ label: "Poll ms",
2807
+ description: "Idle poll interval between claim attempts"
2808
+ },
2809
+ {
2810
+ key: "claimJitterMs",
2811
+ type: "number",
2812
+ label: "Claim jitter ms",
2813
+ description: "Random delay before worker claims (0 = off)"
2814
+ },
2815
+ {
2816
+ key: "scanLimit",
2817
+ type: "number",
2818
+ label: "Scan limit",
2819
+ description: "Max idle rows scanned per claim attempt"
2820
+ }
2821
+ ];
2822
+ function mergeRuntimeParamSpecs(extra) {
2823
+ const byKey = new Map(DEFAULT_RUNTIME_PARAM_SPECS.map((s) => [s.key, { ...s }]));
2824
+ if (Array.isArray(extra)) {
2825
+ for (const raw of extra) {
2826
+ if (!raw || typeof raw !== "object") continue;
2827
+ const key = String(raw.key ?? "").trim();
2828
+ if (!key) continue;
2829
+ const prev = byKey.get(key) ?? {};
2830
+ const type = ["number", "boolean", "string"].includes(raw.type) ? raw.type : prev.type ?? "string";
2831
+ byKey.set(key, {
2832
+ key,
2833
+ type,
2834
+ label: String(raw.label ?? prev.label ?? key),
2835
+ description: raw.description != null ? String(raw.description) : prev.description != null ? String(prev.description) : void 0
2836
+ });
2837
+ }
2838
+ }
2839
+ return Array.from(byKey.values());
2840
+ }
2841
+ function runtimeValuesForSpecs(context, specs = DEFAULT_RUNTIME_PARAM_SPECS) {
2842
+ const rt = ensureTasksRuntime(context);
2843
+ const out = {};
2844
+ for (const s of specs) {
2845
+ if (rt[s.key] !== void 0) out[s.key] = rt[s.key];
2846
+ }
2847
+ return out;
2848
+ }
2849
+ function runtimeParamSpecsFromMetadata(metadata) {
2850
+ const meta = metadata && typeof metadata === "object" ? metadata : null;
2851
+ const raw = meta?.runtimeParams;
2852
+ if (!Array.isArray(raw) || raw.length === 0) {
2853
+ return mergeRuntimeParamSpecs();
2854
+ }
2855
+ return mergeRuntimeParamSpecs(raw);
2856
+ }
2792
2857
  var CONTROL_LANE_TASK_NAMES = [
2793
2858
  "stopRunner",
2794
2859
  "stop",
@@ -2885,12 +2950,15 @@ async function applyRuntimeParam(context, key, value) {
2885
2950
  const reg = context.servicesRegistry;
2886
2951
  if (reg?.rowId && reg?.registryTable) {
2887
2952
  try {
2888
- const loopSnapshot = {};
2953
+ const specs = Array.isArray(context.tasksRuntimeParamSpecs) ? context.tasksRuntimeParamSpecs : DEFAULT_RUNTIME_PARAM_SPECS;
2954
+ const runtimeSnapshot = runtimeValuesForSpecs(context, specs);
2889
2955
  for (const lk of LOOP_RUNTIME_KEYS) {
2890
- if (runtime[lk] !== void 0) loopSnapshot[lk] = runtime[lk];
2956
+ if (runtime[lk] !== void 0 && runtimeSnapshot[lk] === void 0) {
2957
+ runtimeSnapshot[lk] = runtime[lk];
2958
+ }
2891
2959
  }
2892
2960
  await updateServicesRegistryMetadata(context, reg, {
2893
- runtime: loopSnapshot,
2961
+ runtime: runtimeSnapshot,
2894
2962
  runtimeUpdatedAt: (/* @__PURE__ */ new Date()).toISOString()
2895
2963
  });
2896
2964
  applied.push("servicesRegistry");
@@ -3783,18 +3851,25 @@ async function runTasksLoop(context, options) {
3783
3851
  if (hbGroup) {
3784
3852
  const hbIntervalMs = options.runnerHeartbeatIntervalMs ?? 1e4;
3785
3853
  const staleMs = options.runnerHeartbeatStaleMs ?? 45e3;
3786
- const loop0 = readLoopRuntime(context);
3854
+ const runtimeParamSpecs = mergeRuntimeParamSpecs(options.runnerRuntimeParams);
3855
+ context.tasksRuntimeParamSpecs = runtimeParamSpecs;
3787
3856
  const defaultMeta = {
3788
3857
  component: "tasks-runner",
3789
3858
  allowedTasks: allowedTasks?.length ? allowedTasks.join(",") : "all",
3790
3859
  paused: false,
3791
- runtime: {
3792
- maxParallel: loop0.maxParallel,
3793
- pollMs: loop0.pollMs,
3794
- claimJitterMs: loop0.claimJitterMs,
3795
- scanLimit: loop0.scanLimit
3796
- }
3860
+ runtimeParams: runtimeParamSpecs,
3861
+ runtime: runtimeValuesForSpecs(context, runtimeParamSpecs)
3862
+ };
3863
+ const metadata = {
3864
+ ...defaultMeta,
3865
+ ...options.runnerMetadata && typeof options.runnerMetadata === "object" ? options.runnerMetadata : {}
3797
3866
  };
3867
+ if (!Array.isArray(metadata.runtimeParams) || metadata.runtimeParams.length === 0) {
3868
+ metadata.runtimeParams = defaultMeta.runtimeParams;
3869
+ }
3870
+ if (!metadata.runtime || typeof metadata.runtime !== "object") {
3871
+ metadata.runtime = defaultMeta.runtime;
3872
+ }
3798
3873
  registryReg = await registerInServicesRegistry(context, {
3799
3874
  queueName,
3800
3875
  target,
@@ -3804,7 +3879,7 @@ async function runTasksLoop(context, options) {
3804
3879
  staleMs,
3805
3880
  groupMaxInstances: options.runnerGroupMaxInstances,
3806
3881
  enforceMaxInstances: options.runnerEnforceMaxInstances ?? true,
3807
- metadata: options.runnerMetadata ?? defaultMeta
3882
+ metadata
3808
3883
  });
3809
3884
  context.servicesRegistry = registryReg;
3810
3885
  runnerIdentity = {
@@ -4119,6 +4194,7 @@ var TasksManager = class _TasksManager {
4119
4194
  // Annotate the CommonJS export names for ESM import in node:
4120
4195
  0 && (module.exports = {
4121
4196
  AbstractTask,
4197
+ DEFAULT_RUNTIME_PARAM_SPECS,
4122
4198
  LOGGER_RUNTIME_KEYS,
4123
4199
  LOOP_RUNTIME_KEYS,
4124
4200
  SERVICE_TASK_NAMES,
@@ -4153,6 +4229,7 @@ var TasksManager = class _TasksManager {
4153
4229
  listServicesRegistry,
4154
4230
  matchesParsedPattern,
4155
4231
  mergeAllowedTasksWithServiceTasks,
4232
+ mergeRuntimeParamSpecs,
4156
4233
  nextTimeMatch,
4157
4234
  normalizeAllowedTasks,
4158
4235
  queueToTableNames,
@@ -4166,6 +4243,8 @@ var TasksManager = class _TasksManager {
4166
4243
  resolveSteps,
4167
4244
  runNodeTaskScript,
4168
4245
  runTasksLoop,
4246
+ runtimeParamSpecsFromMetadata,
4247
+ runtimeValuesForSpecs,
4169
4248
  taskHistoryInsertFromQueueRow,
4170
4249
  timeMatcher,
4171
4250
  touchRunnerHeartbeat,