@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/cli-runner.cjs +74 -11
- package/dist/cli-runner.cjs.map +1 -1
- package/dist/cli-runner.js +74 -11
- package/dist/cli-runner.js.map +1 -1
- package/dist/index.cjs +90 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +86 -11
- package/dist/index.js.map +1 -1
- package/dist/tasks.cjs +90 -11
- package/dist/tasks.cjs.map +1 -1
- package/dist/tasks.js +86 -11
- package/dist/tasks.js.map +1 -1
- package/package.json +1 -1
package/dist/tasks.js
CHANGED
|
@@ -2700,6 +2700,67 @@ var LOGGER_RUNTIME_KEYS = [
|
|
|
2700
2700
|
"progressWithTimes",
|
|
2701
2701
|
"progressThrottleMs"
|
|
2702
2702
|
];
|
|
2703
|
+
var DEFAULT_RUNTIME_PARAM_SPECS = [
|
|
2704
|
+
{
|
|
2705
|
+
key: "maxParallel",
|
|
2706
|
+
type: "number",
|
|
2707
|
+
label: "Max parallel",
|
|
2708
|
+
description: "Worker-lane concurrency (how many tasks claim at once)"
|
|
2709
|
+
},
|
|
2710
|
+
{
|
|
2711
|
+
key: "pollMs",
|
|
2712
|
+
type: "number",
|
|
2713
|
+
label: "Poll ms",
|
|
2714
|
+
description: "Idle poll interval between claim attempts"
|
|
2715
|
+
},
|
|
2716
|
+
{
|
|
2717
|
+
key: "claimJitterMs",
|
|
2718
|
+
type: "number",
|
|
2719
|
+
label: "Claim jitter ms",
|
|
2720
|
+
description: "Random delay before worker claims (0 = off)"
|
|
2721
|
+
},
|
|
2722
|
+
{
|
|
2723
|
+
key: "scanLimit",
|
|
2724
|
+
type: "number",
|
|
2725
|
+
label: "Scan limit",
|
|
2726
|
+
description: "Max idle rows scanned per claim attempt"
|
|
2727
|
+
}
|
|
2728
|
+
];
|
|
2729
|
+
function mergeRuntimeParamSpecs(extra) {
|
|
2730
|
+
const byKey = new Map(DEFAULT_RUNTIME_PARAM_SPECS.map((s) => [s.key, { ...s }]));
|
|
2731
|
+
if (Array.isArray(extra)) {
|
|
2732
|
+
for (const raw of extra) {
|
|
2733
|
+
if (!raw || typeof raw !== "object") continue;
|
|
2734
|
+
const key = String(raw.key ?? "").trim();
|
|
2735
|
+
if (!key) continue;
|
|
2736
|
+
const prev = byKey.get(key) ?? {};
|
|
2737
|
+
const type = ["number", "boolean", "string"].includes(raw.type) ? raw.type : prev.type ?? "string";
|
|
2738
|
+
byKey.set(key, {
|
|
2739
|
+
key,
|
|
2740
|
+
type,
|
|
2741
|
+
label: String(raw.label ?? prev.label ?? key),
|
|
2742
|
+
description: raw.description != null ? String(raw.description) : prev.description != null ? String(prev.description) : void 0
|
|
2743
|
+
});
|
|
2744
|
+
}
|
|
2745
|
+
}
|
|
2746
|
+
return Array.from(byKey.values());
|
|
2747
|
+
}
|
|
2748
|
+
function runtimeValuesForSpecs(context, specs = DEFAULT_RUNTIME_PARAM_SPECS) {
|
|
2749
|
+
const rt = ensureTasksRuntime(context);
|
|
2750
|
+
const out = {};
|
|
2751
|
+
for (const s of specs) {
|
|
2752
|
+
if (rt[s.key] !== void 0) out[s.key] = rt[s.key];
|
|
2753
|
+
}
|
|
2754
|
+
return out;
|
|
2755
|
+
}
|
|
2756
|
+
function runtimeParamSpecsFromMetadata(metadata) {
|
|
2757
|
+
const meta = metadata && typeof metadata === "object" ? metadata : null;
|
|
2758
|
+
const raw = meta?.runtimeParams;
|
|
2759
|
+
if (!Array.isArray(raw) || raw.length === 0) {
|
|
2760
|
+
return mergeRuntimeParamSpecs();
|
|
2761
|
+
}
|
|
2762
|
+
return mergeRuntimeParamSpecs(raw);
|
|
2763
|
+
}
|
|
2703
2764
|
var CONTROL_LANE_TASK_NAMES = [
|
|
2704
2765
|
"stopRunner",
|
|
2705
2766
|
"stop",
|
|
@@ -2796,12 +2857,15 @@ async function applyRuntimeParam(context, key, value) {
|
|
|
2796
2857
|
const reg = context.servicesRegistry;
|
|
2797
2858
|
if (reg?.rowId && reg?.registryTable) {
|
|
2798
2859
|
try {
|
|
2799
|
-
const
|
|
2860
|
+
const specs = Array.isArray(context.tasksRuntimeParamSpecs) ? context.tasksRuntimeParamSpecs : DEFAULT_RUNTIME_PARAM_SPECS;
|
|
2861
|
+
const runtimeSnapshot = runtimeValuesForSpecs(context, specs);
|
|
2800
2862
|
for (const lk of LOOP_RUNTIME_KEYS) {
|
|
2801
|
-
if (runtime[lk] !== void 0
|
|
2863
|
+
if (runtime[lk] !== void 0 && runtimeSnapshot[lk] === void 0) {
|
|
2864
|
+
runtimeSnapshot[lk] = runtime[lk];
|
|
2865
|
+
}
|
|
2802
2866
|
}
|
|
2803
2867
|
await updateServicesRegistryMetadata(context, reg, {
|
|
2804
|
-
runtime:
|
|
2868
|
+
runtime: runtimeSnapshot,
|
|
2805
2869
|
runtimeUpdatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
2806
2870
|
});
|
|
2807
2871
|
applied.push("servicesRegistry");
|
|
@@ -3694,18 +3758,25 @@ async function runTasksLoop(context, options) {
|
|
|
3694
3758
|
if (hbGroup) {
|
|
3695
3759
|
const hbIntervalMs = options.runnerHeartbeatIntervalMs ?? 1e4;
|
|
3696
3760
|
const staleMs = options.runnerHeartbeatStaleMs ?? 45e3;
|
|
3697
|
-
const
|
|
3761
|
+
const runtimeParamSpecs = mergeRuntimeParamSpecs(options.runnerRuntimeParams);
|
|
3762
|
+
context.tasksRuntimeParamSpecs = runtimeParamSpecs;
|
|
3698
3763
|
const defaultMeta = {
|
|
3699
3764
|
component: "tasks-runner",
|
|
3700
3765
|
allowedTasks: allowedTasks?.length ? allowedTasks.join(",") : "all",
|
|
3701
3766
|
paused: false,
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
}
|
|
3767
|
+
runtimeParams: runtimeParamSpecs,
|
|
3768
|
+
runtime: runtimeValuesForSpecs(context, runtimeParamSpecs)
|
|
3769
|
+
};
|
|
3770
|
+
const metadata = {
|
|
3771
|
+
...defaultMeta,
|
|
3772
|
+
...options.runnerMetadata && typeof options.runnerMetadata === "object" ? options.runnerMetadata : {}
|
|
3708
3773
|
};
|
|
3774
|
+
if (!Array.isArray(metadata.runtimeParams) || metadata.runtimeParams.length === 0) {
|
|
3775
|
+
metadata.runtimeParams = defaultMeta.runtimeParams;
|
|
3776
|
+
}
|
|
3777
|
+
if (!metadata.runtime || typeof metadata.runtime !== "object") {
|
|
3778
|
+
metadata.runtime = defaultMeta.runtime;
|
|
3779
|
+
}
|
|
3709
3780
|
registryReg = await registerInServicesRegistry(context, {
|
|
3710
3781
|
queueName,
|
|
3711
3782
|
target,
|
|
@@ -3715,7 +3786,7 @@ async function runTasksLoop(context, options) {
|
|
|
3715
3786
|
staleMs,
|
|
3716
3787
|
groupMaxInstances: options.runnerGroupMaxInstances,
|
|
3717
3788
|
enforceMaxInstances: options.runnerEnforceMaxInstances ?? true,
|
|
3718
|
-
metadata
|
|
3789
|
+
metadata
|
|
3719
3790
|
});
|
|
3720
3791
|
context.servicesRegistry = registryReg;
|
|
3721
3792
|
runnerIdentity = {
|
|
@@ -4029,6 +4100,7 @@ var TasksManager = class _TasksManager {
|
|
|
4029
4100
|
};
|
|
4030
4101
|
export {
|
|
4031
4102
|
AbstractTask,
|
|
4103
|
+
DEFAULT_RUNTIME_PARAM_SPECS,
|
|
4032
4104
|
LOGGER_RUNTIME_KEYS,
|
|
4033
4105
|
LOOP_RUNTIME_KEYS,
|
|
4034
4106
|
SERVICE_TASK_NAMES,
|
|
@@ -4063,6 +4135,7 @@ export {
|
|
|
4063
4135
|
listServicesRegistry,
|
|
4064
4136
|
matchesParsedPattern,
|
|
4065
4137
|
mergeAllowedTasksWithServiceTasks,
|
|
4138
|
+
mergeRuntimeParamSpecs,
|
|
4066
4139
|
nextTimeMatch,
|
|
4067
4140
|
normalizeAllowedTasks,
|
|
4068
4141
|
queueToTableNames,
|
|
@@ -4076,6 +4149,8 @@ export {
|
|
|
4076
4149
|
resolveSteps,
|
|
4077
4150
|
runNodeTaskScript,
|
|
4078
4151
|
runTasksLoop,
|
|
4152
|
+
runtimeParamSpecsFromMetadata,
|
|
4153
|
+
runtimeValuesForSpecs,
|
|
4079
4154
|
taskHistoryInsertFromQueueRow,
|
|
4080
4155
|
timeMatcher,
|
|
4081
4156
|
touchServicesRegistry as touchRunnerHeartbeat,
|