@nmakarov/cli-toolkit 0.70.0 → 0.72.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,
@@ -608,6 +612,9 @@ var DEFAULT_GROUP_MAX_INSTANCES = {
608
612
  harvest: 1,
609
613
  harvester: 0,
610
614
  loader: 0,
615
+ toolkit: 0,
616
+ photocare: 0,
617
+ /** @deprecated use photocare */
611
618
  photos: 0,
612
619
  photosprocessor: 0,
613
620
  ingest: 0
@@ -2789,6 +2796,67 @@ var LOGGER_RUNTIME_KEYS = [
2789
2796
  "progressWithTimes",
2790
2797
  "progressThrottleMs"
2791
2798
  ];
2799
+ var DEFAULT_RUNTIME_PARAM_SPECS = [
2800
+ {
2801
+ key: "maxParallel",
2802
+ type: "number",
2803
+ label: "Max parallel",
2804
+ description: "Worker-lane concurrency (how many tasks claim at once)"
2805
+ },
2806
+ {
2807
+ key: "pollMs",
2808
+ type: "number",
2809
+ label: "Poll ms",
2810
+ description: "Idle poll interval between claim attempts"
2811
+ },
2812
+ {
2813
+ key: "claimJitterMs",
2814
+ type: "number",
2815
+ label: "Claim jitter ms",
2816
+ description: "Random delay before worker claims (0 = off)"
2817
+ },
2818
+ {
2819
+ key: "scanLimit",
2820
+ type: "number",
2821
+ label: "Scan limit",
2822
+ description: "Max idle rows scanned per claim attempt"
2823
+ }
2824
+ ];
2825
+ function mergeRuntimeParamSpecs(extra) {
2826
+ const byKey = new Map(DEFAULT_RUNTIME_PARAM_SPECS.map((s) => [s.key, { ...s }]));
2827
+ if (Array.isArray(extra)) {
2828
+ for (const raw of extra) {
2829
+ if (!raw || typeof raw !== "object") continue;
2830
+ const key = String(raw.key ?? "").trim();
2831
+ if (!key) continue;
2832
+ const prev = byKey.get(key) ?? {};
2833
+ const type = ["number", "boolean", "string"].includes(raw.type) ? raw.type : prev.type ?? "string";
2834
+ byKey.set(key, {
2835
+ key,
2836
+ type,
2837
+ label: String(raw.label ?? prev.label ?? key),
2838
+ description: raw.description != null ? String(raw.description) : prev.description != null ? String(prev.description) : void 0
2839
+ });
2840
+ }
2841
+ }
2842
+ return Array.from(byKey.values());
2843
+ }
2844
+ function runtimeValuesForSpecs(context, specs = DEFAULT_RUNTIME_PARAM_SPECS) {
2845
+ const rt = ensureTasksRuntime(context);
2846
+ const out = {};
2847
+ for (const s of specs) {
2848
+ if (rt[s.key] !== void 0) out[s.key] = rt[s.key];
2849
+ }
2850
+ return out;
2851
+ }
2852
+ function runtimeParamSpecsFromMetadata(metadata) {
2853
+ const meta = metadata && typeof metadata === "object" ? metadata : null;
2854
+ const raw = meta?.runtimeParams;
2855
+ if (!Array.isArray(raw) || raw.length === 0) {
2856
+ return mergeRuntimeParamSpecs();
2857
+ }
2858
+ return mergeRuntimeParamSpecs(raw);
2859
+ }
2792
2860
  var CONTROL_LANE_TASK_NAMES = [
2793
2861
  "stopRunner",
2794
2862
  "stop",
@@ -2885,12 +2953,15 @@ async function applyRuntimeParam(context, key, value) {
2885
2953
  const reg = context.servicesRegistry;
2886
2954
  if (reg?.rowId && reg?.registryTable) {
2887
2955
  try {
2888
- const loopSnapshot = {};
2956
+ const specs = Array.isArray(context.tasksRuntimeParamSpecs) ? context.tasksRuntimeParamSpecs : DEFAULT_RUNTIME_PARAM_SPECS;
2957
+ const runtimeSnapshot = runtimeValuesForSpecs(context, specs);
2889
2958
  for (const lk of LOOP_RUNTIME_KEYS) {
2890
- if (runtime[lk] !== void 0) loopSnapshot[lk] = runtime[lk];
2959
+ if (runtime[lk] !== void 0 && runtimeSnapshot[lk] === void 0) {
2960
+ runtimeSnapshot[lk] = runtime[lk];
2961
+ }
2891
2962
  }
2892
2963
  await updateServicesRegistryMetadata(context, reg, {
2893
- runtime: loopSnapshot,
2964
+ runtime: runtimeSnapshot,
2894
2965
  runtimeUpdatedAt: (/* @__PURE__ */ new Date()).toISOString()
2895
2966
  });
2896
2967
  applied.push("servicesRegistry");
@@ -3783,18 +3854,25 @@ async function runTasksLoop(context, options) {
3783
3854
  if (hbGroup) {
3784
3855
  const hbIntervalMs = options.runnerHeartbeatIntervalMs ?? 1e4;
3785
3856
  const staleMs = options.runnerHeartbeatStaleMs ?? 45e3;
3786
- const loop0 = readLoopRuntime(context);
3857
+ const runtimeParamSpecs = mergeRuntimeParamSpecs(options.runnerRuntimeParams);
3858
+ context.tasksRuntimeParamSpecs = runtimeParamSpecs;
3787
3859
  const defaultMeta = {
3788
3860
  component: "tasks-runner",
3789
3861
  allowedTasks: allowedTasks?.length ? allowedTasks.join(",") : "all",
3790
3862
  paused: false,
3791
- runtime: {
3792
- maxParallel: loop0.maxParallel,
3793
- pollMs: loop0.pollMs,
3794
- claimJitterMs: loop0.claimJitterMs,
3795
- scanLimit: loop0.scanLimit
3796
- }
3863
+ runtimeParams: runtimeParamSpecs,
3864
+ runtime: runtimeValuesForSpecs(context, runtimeParamSpecs)
3865
+ };
3866
+ const metadata = {
3867
+ ...defaultMeta,
3868
+ ...options.runnerMetadata && typeof options.runnerMetadata === "object" ? options.runnerMetadata : {}
3797
3869
  };
3870
+ if (!Array.isArray(metadata.runtimeParams) || metadata.runtimeParams.length === 0) {
3871
+ metadata.runtimeParams = defaultMeta.runtimeParams;
3872
+ }
3873
+ if (!metadata.runtime || typeof metadata.runtime !== "object") {
3874
+ metadata.runtime = defaultMeta.runtime;
3875
+ }
3798
3876
  registryReg = await registerInServicesRegistry(context, {
3799
3877
  queueName,
3800
3878
  target,
@@ -3804,7 +3882,7 @@ async function runTasksLoop(context, options) {
3804
3882
  staleMs,
3805
3883
  groupMaxInstances: options.runnerGroupMaxInstances,
3806
3884
  enforceMaxInstances: options.runnerEnforceMaxInstances ?? true,
3807
- metadata: options.runnerMetadata ?? defaultMeta
3885
+ metadata
3808
3886
  });
3809
3887
  context.servicesRegistry = registryReg;
3810
3888
  runnerIdentity = {
@@ -4119,6 +4197,7 @@ var TasksManager = class _TasksManager {
4119
4197
  // Annotate the CommonJS export names for ESM import in node:
4120
4198
  0 && (module.exports = {
4121
4199
  AbstractTask,
4200
+ DEFAULT_RUNTIME_PARAM_SPECS,
4122
4201
  LOGGER_RUNTIME_KEYS,
4123
4202
  LOOP_RUNTIME_KEYS,
4124
4203
  SERVICE_TASK_NAMES,
@@ -4153,6 +4232,7 @@ var TasksManager = class _TasksManager {
4153
4232
  listServicesRegistry,
4154
4233
  matchesParsedPattern,
4155
4234
  mergeAllowedTasksWithServiceTasks,
4235
+ mergeRuntimeParamSpecs,
4156
4236
  nextTimeMatch,
4157
4237
  normalizeAllowedTasks,
4158
4238
  queueToTableNames,
@@ -4166,6 +4246,8 @@ var TasksManager = class _TasksManager {
4166
4246
  resolveSteps,
4167
4247
  runNodeTaskScript,
4168
4248
  runTasksLoop,
4249
+ runtimeParamSpecsFromMetadata,
4250
+ runtimeValuesForSpecs,
4169
4251
  taskHistoryInsertFromQueueRow,
4170
4252
  timeMatcher,
4171
4253
  touchRunnerHeartbeat,