@cadenza.io/core 3.1.8 → 3.2.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/index.js +42 -60
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -60
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -201,14 +201,13 @@ var SignalBroker = class _SignalBroker {
|
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
203
|
execute(signal, context) {
|
|
204
|
-
var _a, _b, _c, _d;
|
|
205
204
|
const isMeta = signal.includes("meta.");
|
|
206
205
|
const isSubMeta = signal.includes("sub_meta.") || context.__isSubMeta;
|
|
207
|
-
const isMetric =
|
|
206
|
+
const isMetric = context.__signalEmission?.isMetric;
|
|
208
207
|
if (!isSubMeta && (!isMeta || this.debug)) {
|
|
209
208
|
const emittedAt = Date.now();
|
|
210
209
|
context.__signalEmission = {
|
|
211
|
-
...
|
|
210
|
+
...context.__signalEmission ?? {},
|
|
212
211
|
signalName: signal,
|
|
213
212
|
emittedAt: formatTimestamp(emittedAt),
|
|
214
213
|
consumed: false,
|
|
@@ -223,7 +222,7 @@ var SignalBroker = class _SignalBroker {
|
|
|
223
222
|
}
|
|
224
223
|
if (this.debug && (!isMetric && !isSubMeta || this.verbose)) {
|
|
225
224
|
console.log(
|
|
226
|
-
`EMITTING ${signal} to listeners ${
|
|
225
|
+
`EMITTING ${signal} to listeners ${this.signalObservers.get(signal)?.tasks.size ?? 0} with context ${this.verbose ? JSON.stringify(context) : JSON.stringify(context).slice(0, 100)}`
|
|
227
226
|
);
|
|
228
227
|
}
|
|
229
228
|
let executed;
|
|
@@ -232,7 +231,7 @@ var SignalBroker = class _SignalBroker {
|
|
|
232
231
|
const parts = signal.slice(0, Math.max(signal.lastIndexOf(":"), signal.lastIndexOf("."))).split(".");
|
|
233
232
|
for (let i = parts.length; i > -1; i--) {
|
|
234
233
|
const parent = parts.slice(0, i).join(".");
|
|
235
|
-
executed =
|
|
234
|
+
executed = this.executeListener(parent + ".*", context) || executed;
|
|
236
235
|
}
|
|
237
236
|
}
|
|
238
237
|
return executed;
|
|
@@ -496,29 +495,26 @@ var GraphRun = class {
|
|
|
496
495
|
}
|
|
497
496
|
// Composite function
|
|
498
497
|
destroy() {
|
|
499
|
-
|
|
500
|
-
(_a = this.graph) == null ? void 0 : _a.destroy();
|
|
498
|
+
this.graph?.destroy();
|
|
501
499
|
this.graph = void 0;
|
|
502
500
|
this.exporter = void 0;
|
|
503
501
|
}
|
|
504
502
|
// Composite function
|
|
505
503
|
log() {
|
|
506
|
-
var _a;
|
|
507
504
|
console.log("vvvvvvvvvvvvvvvvv");
|
|
508
505
|
console.log("GraphRun");
|
|
509
506
|
console.log("vvvvvvvvvvvvvvvvv");
|
|
510
|
-
|
|
507
|
+
this.graph?.log();
|
|
511
508
|
console.log("=================");
|
|
512
509
|
}
|
|
513
510
|
// Memento
|
|
514
511
|
export() {
|
|
515
|
-
var _a, _b;
|
|
516
512
|
if (this.exporter && this.graph) {
|
|
517
513
|
const data = this.strategy.export();
|
|
518
514
|
return {
|
|
519
515
|
__id: this.id,
|
|
520
|
-
__label:
|
|
521
|
-
__graph:
|
|
516
|
+
__label: data.__startTime ?? this.id,
|
|
517
|
+
__graph: this.exporter?.exportGraph(this.graph),
|
|
522
518
|
__data: data
|
|
523
519
|
};
|
|
524
520
|
}
|
|
@@ -698,9 +694,8 @@ function sleep(ms) {
|
|
|
698
694
|
// src/graph/execution/GraphNode.ts
|
|
699
695
|
var GraphNode = class _GraphNode extends SignalEmitter {
|
|
700
696
|
constructor(task, context, routineExecId, prevNodes = [], debug = false, verbose = false) {
|
|
701
|
-
var _a;
|
|
702
697
|
super(
|
|
703
|
-
task.isMeta && !debug || task.isSubMeta ||
|
|
698
|
+
task.isMeta && !debug || task.isSubMeta || context?.getMetadata()?.__isSubMeta
|
|
704
699
|
);
|
|
705
700
|
this.divided = false;
|
|
706
701
|
this.splitGroupId = "";
|
|
@@ -777,7 +772,6 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
777
772
|
return this.task.getTag(this.context);
|
|
778
773
|
}
|
|
779
774
|
scheduleOn(layer) {
|
|
780
|
-
var _a, _b, _c;
|
|
781
775
|
let shouldSchedule = true;
|
|
782
776
|
const nodes = layer.getNodesByRoutineExecId(this.routineExecId);
|
|
783
777
|
for (const node of nodes) {
|
|
@@ -800,7 +794,7 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
800
794
|
data: {
|
|
801
795
|
uuid: this.id,
|
|
802
796
|
routineExecutionId: this.routineExecId,
|
|
803
|
-
executionTraceId:
|
|
797
|
+
executionTraceId: context.__executionTraceId ?? context.__metadata?.__executionTraceId,
|
|
804
798
|
context: this.previousNodes.length === 0 ? this.context.id : this.context.export(),
|
|
805
799
|
taskName: this.task.name,
|
|
806
800
|
taskVersion: this.task.version,
|
|
@@ -824,7 +818,7 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
824
818
|
}
|
|
825
819
|
});
|
|
826
820
|
});
|
|
827
|
-
if (
|
|
821
|
+
if (context.__signalEmission?.consumed === false && (!this.isMeta() || this.debug)) {
|
|
828
822
|
this.emitMetricsWithMetadata("meta.node.consumed_signal", {
|
|
829
823
|
data: {
|
|
830
824
|
signalName: context.__signalEmission.signalName,
|
|
@@ -971,7 +965,7 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
971
965
|
this.emitWithMetadata.bind(this),
|
|
972
966
|
this.onProgress.bind(this)
|
|
973
967
|
);
|
|
974
|
-
if (
|
|
968
|
+
if (result?.errored || result?.failed) {
|
|
975
969
|
return this.retry(result);
|
|
976
970
|
}
|
|
977
971
|
return result;
|
|
@@ -987,9 +981,8 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
987
981
|
}
|
|
988
982
|
}
|
|
989
983
|
emitWithMetadata(signal, ctx) {
|
|
990
|
-
var _a, _b, _c;
|
|
991
984
|
const data = { ...ctx };
|
|
992
|
-
if (!
|
|
985
|
+
if (!this.task?.isHidden) {
|
|
993
986
|
data.__signalEmission = {
|
|
994
987
|
taskName: this.task.name,
|
|
995
988
|
taskVersion: this.task.version,
|
|
@@ -999,15 +992,14 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
999
992
|
data.__metadata = {
|
|
1000
993
|
...data.__metadata,
|
|
1001
994
|
__routineExecId: this.routineExecId,
|
|
1002
|
-
__executionTraceId:
|
|
995
|
+
__executionTraceId: context.__metadata?.__executionTraceId ?? context.__executionTraceId
|
|
1003
996
|
};
|
|
1004
997
|
}
|
|
1005
998
|
this.emit(signal, data);
|
|
1006
999
|
}
|
|
1007
1000
|
emitMetricsWithMetadata(signal, ctx) {
|
|
1008
|
-
var _a, _b, _c;
|
|
1009
1001
|
const data = { ...ctx };
|
|
1010
|
-
if (!
|
|
1002
|
+
if (!this.task?.isHidden) {
|
|
1011
1003
|
data.__signalEmission = {
|
|
1012
1004
|
taskName: this.task.name,
|
|
1013
1005
|
taskVersion: this.task.version,
|
|
@@ -1018,13 +1010,12 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
1018
1010
|
data.__metadata = {
|
|
1019
1011
|
...data.__metadata,
|
|
1020
1012
|
__routineExecId: this.routineExecId,
|
|
1021
|
-
__executionTraceId:
|
|
1013
|
+
__executionTraceId: context.__metadata?.__executionTraceId ?? context.__executionTraceId
|
|
1022
1014
|
};
|
|
1023
1015
|
}
|
|
1024
1016
|
this.emitMetrics(signal, data);
|
|
1025
1017
|
}
|
|
1026
1018
|
onProgress(progress) {
|
|
1027
|
-
var _a, _b;
|
|
1028
1019
|
progress = Math.min(Math.max(0, progress), 1);
|
|
1029
1020
|
this.emitMetricsWithMetadata("meta.node.progress", {
|
|
1030
1021
|
data: {
|
|
@@ -1038,7 +1029,7 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
1038
1029
|
`meta.node.routine_execution_progress:${this.routineExecId}`,
|
|
1039
1030
|
{
|
|
1040
1031
|
data: {
|
|
1041
|
-
progress: progress * this.task.progressWeight / (
|
|
1032
|
+
progress: progress * this.task.progressWeight / (this.layer?.getIdenticalNodes(this).length ?? 1)
|
|
1042
1033
|
},
|
|
1043
1034
|
filter: {
|
|
1044
1035
|
uuid: this.routineExecId
|
|
@@ -1121,9 +1112,8 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
1121
1112
|
}
|
|
1122
1113
|
}
|
|
1123
1114
|
divide() {
|
|
1124
|
-
var _a;
|
|
1125
1115
|
const newNodes = [];
|
|
1126
|
-
if (
|
|
1116
|
+
if (this.result?.next && typeof this.result.next === "function") {
|
|
1127
1117
|
const generator = this.result;
|
|
1128
1118
|
let current = generator.next();
|
|
1129
1119
|
if (current instanceof Promise) {
|
|
@@ -1237,11 +1227,10 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
1237
1227
|
return newNodes;
|
|
1238
1228
|
}
|
|
1239
1229
|
differentiate(task) {
|
|
1240
|
-
var _a, _b;
|
|
1241
1230
|
this.task = task;
|
|
1242
1231
|
this.retryCount = task.retryCount;
|
|
1243
1232
|
this.retryDelay = task.retryDelay;
|
|
1244
|
-
this.silent = task.isMeta && !this.debug || task.isSubMeta ||
|
|
1233
|
+
this.silent = task.isMeta && !this.debug || task.isSubMeta || this.context?.getMetadata()?.__isSubMeta;
|
|
1245
1234
|
return this;
|
|
1246
1235
|
}
|
|
1247
1236
|
migrate(ctx) {
|
|
@@ -2370,7 +2359,6 @@ var GraphRunner = class extends SignalEmitter {
|
|
|
2370
2359
|
* @edge Empty tasks warns no-op.
|
|
2371
2360
|
*/
|
|
2372
2361
|
addTasks(tasks, context = {}) {
|
|
2373
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
2374
2362
|
let _tasks = Array.isArray(tasks) ? tasks : [tasks];
|
|
2375
2363
|
if (_tasks.length === 0) {
|
|
2376
2364
|
console.warn("No tasks/routines to add.");
|
|
@@ -2392,10 +2380,10 @@ var GraphRunner = class extends SignalEmitter {
|
|
|
2392
2380
|
});
|
|
2393
2381
|
const isSubMeta = allTasks.some((t) => t.isSubMeta) || !!context.__isSubMeta;
|
|
2394
2382
|
context.__isSubMeta = isSubMeta;
|
|
2395
|
-
const isNewTrace = !context.__routineExecId && !
|
|
2396
|
-
const executionTraceId =
|
|
2383
|
+
const isNewTrace = !context.__routineExecId && !context.__metadata?.__executionTraceId && !context.__executionTraceId;
|
|
2384
|
+
const executionTraceId = context.__metadata?.__executionTraceId ?? context.__executionTraceId ?? (0, import_uuid4.v4)();
|
|
2397
2385
|
context.__executionTraceId = executionTraceId;
|
|
2398
|
-
const routineExecId =
|
|
2386
|
+
const routineExecId = context.__routineExecId ?? (0, import_uuid4.v4)();
|
|
2399
2387
|
context.__routineExecId = routineExecId;
|
|
2400
2388
|
const ctx = new GraphContext(context || {});
|
|
2401
2389
|
if (!isSubMeta) {
|
|
@@ -2406,9 +2394,9 @@ var GraphRunner = class extends SignalEmitter {
|
|
|
2406
2394
|
uuid: executionTraceId,
|
|
2407
2395
|
issuer_type: "service",
|
|
2408
2396
|
// TODO: Add issuer type
|
|
2409
|
-
issuer_id:
|
|
2397
|
+
issuer_id: context.__metadata?.__issuerId ?? context.__issuerId ?? null,
|
|
2410
2398
|
issued_at: formatTimestamp(Date.now()),
|
|
2411
|
-
intent:
|
|
2399
|
+
intent: context.__metadata?.__intent ?? context.__intent ?? null,
|
|
2412
2400
|
context: contextData,
|
|
2413
2401
|
is_meta: isMeta
|
|
2414
2402
|
},
|
|
@@ -2425,7 +2413,7 @@ var GraphRunner = class extends SignalEmitter {
|
|
|
2425
2413
|
isMeta,
|
|
2426
2414
|
executionTraceId,
|
|
2427
2415
|
context: isNewTrace ? contextData.id : contextData,
|
|
2428
|
-
previousRoutineExecution:
|
|
2416
|
+
previousRoutineExecution: context.__localRoutineExecId ?? context.__metadata?.__routineExecId ?? null,
|
|
2429
2417
|
// TODO: There is a chance this is not added to the database yet...
|
|
2430
2418
|
created: formatTimestamp(Date.now())
|
|
2431
2419
|
},
|
|
@@ -2449,7 +2437,7 @@ var GraphRunner = class extends SignalEmitter {
|
|
|
2449
2437
|
*/
|
|
2450
2438
|
run(tasks, context) {
|
|
2451
2439
|
if (tasks) {
|
|
2452
|
-
this.addTasks(tasks, context
|
|
2440
|
+
this.addTasks(tasks, context ?? {});
|
|
2453
2441
|
}
|
|
2454
2442
|
if (this.isRunning) {
|
|
2455
2443
|
return this.currentRun;
|
|
@@ -2493,12 +2481,11 @@ var GraphRunner = class extends SignalEmitter {
|
|
|
2493
2481
|
}
|
|
2494
2482
|
// TODO This should not live here. This is deputy related.
|
|
2495
2483
|
startRun(context, emit) {
|
|
2496
|
-
var _a, _b, _c;
|
|
2497
2484
|
if (context.__task || context.__routine) {
|
|
2498
|
-
const routine =
|
|
2485
|
+
const routine = context.__task ?? context.__routine;
|
|
2499
2486
|
delete context.__task;
|
|
2500
2487
|
delete context.__routine;
|
|
2501
|
-
context.__routineExecId =
|
|
2488
|
+
context.__routineExecId = context.__metadata?.__deputyExecId ?? null;
|
|
2502
2489
|
context.__isDeputy = true;
|
|
2503
2490
|
this.run(routine, context);
|
|
2504
2491
|
return true;
|
|
@@ -2724,22 +2711,20 @@ var GraphLayerIterator = class {
|
|
|
2724
2711
|
return this.currentLayer;
|
|
2725
2712
|
}
|
|
2726
2713
|
getFirst() {
|
|
2727
|
-
var _a;
|
|
2728
2714
|
if (!this.currentLayer) {
|
|
2729
2715
|
this.currentLayer = this.graph;
|
|
2730
2716
|
}
|
|
2731
2717
|
while (this.hasPrevious()) {
|
|
2732
|
-
this.currentLayer =
|
|
2718
|
+
this.currentLayer = this.currentLayer?.getPreceding();
|
|
2733
2719
|
}
|
|
2734
2720
|
return this.currentLayer;
|
|
2735
2721
|
}
|
|
2736
2722
|
getLast() {
|
|
2737
|
-
var _a;
|
|
2738
2723
|
if (!this.currentLayer) {
|
|
2739
2724
|
this.currentLayer = this.graph;
|
|
2740
2725
|
}
|
|
2741
2726
|
while (this.hasNext()) {
|
|
2742
|
-
this.currentLayer =
|
|
2727
|
+
this.currentLayer = this.currentLayer?.getNext();
|
|
2743
2728
|
}
|
|
2744
2729
|
return this.currentLayer;
|
|
2745
2730
|
}
|
|
@@ -2828,7 +2813,7 @@ var GraphLayer = class _GraphLayer extends ExecutionChain {
|
|
|
2828
2813
|
this.nodes = [];
|
|
2829
2814
|
if (this.hasNext) {
|
|
2830
2815
|
const layer = this.getNext();
|
|
2831
|
-
layer
|
|
2816
|
+
layer?.destroy();
|
|
2832
2817
|
}
|
|
2833
2818
|
this.decouple();
|
|
2834
2819
|
}
|
|
@@ -2991,8 +2976,7 @@ var GraphRunStrategy = class {
|
|
|
2991
2976
|
this.graphBuilder.addNode(node);
|
|
2992
2977
|
}
|
|
2993
2978
|
updateRunInstance() {
|
|
2994
|
-
|
|
2995
|
-
(_a = this.runInstance) == null ? void 0 : _a.setGraph(this.graphBuilder.getResult());
|
|
2979
|
+
this.runInstance?.setGraph(this.graphBuilder.getResult());
|
|
2996
2980
|
}
|
|
2997
2981
|
};
|
|
2998
2982
|
|
|
@@ -3017,20 +3001,19 @@ var ThrottleEngine = class _ThrottleEngine {
|
|
|
3017
3001
|
this.maxConcurrencyPerTag[tag] = limit;
|
|
3018
3002
|
}
|
|
3019
3003
|
throttle(fn, node, tag = "default") {
|
|
3020
|
-
var _a, _b
|
|
3004
|
+
var _a, _b;
|
|
3021
3005
|
const functionPromise = new Promise((resolve) => {
|
|
3022
3006
|
this.functionIdToPromiseResolve[node.id] = resolve;
|
|
3023
3007
|
});
|
|
3024
|
-
(
|
|
3008
|
+
(_a = this.queues)[tag] ?? (_a[tag] = []);
|
|
3025
3009
|
this.queues[tag].push([fn, node]);
|
|
3026
|
-
(
|
|
3010
|
+
(_b = this.maxConcurrencyPerTag)[tag] ?? (_b[tag] = 1);
|
|
3027
3011
|
this.processQueue(tag);
|
|
3028
3012
|
return functionPromise;
|
|
3029
3013
|
}
|
|
3030
3014
|
processQueue(tag) {
|
|
3031
|
-
var _a, _b, _c, _d, _e;
|
|
3032
3015
|
const maxAllowed = this.maxConcurrencyPerTag[tag];
|
|
3033
|
-
while ((
|
|
3016
|
+
while ((this.queues[tag]?.length ?? 0) > 0 && (this.runningCounts[tag] ?? 0) < maxAllowed) {
|
|
3034
3017
|
this.runningCounts[tag] = (this.runningCounts[tag] || 0) + 1;
|
|
3035
3018
|
const item = this.queues[tag].shift();
|
|
3036
3019
|
this.process(item).then(() => {
|
|
@@ -3038,7 +3021,7 @@ var ThrottleEngine = class _ThrottleEngine {
|
|
|
3038
3021
|
this.processQueue(tag);
|
|
3039
3022
|
});
|
|
3040
3023
|
}
|
|
3041
|
-
if ((
|
|
3024
|
+
if ((this.queues[tag]?.length ?? 0) === 0 && this.runningCounts[tag] === 0) {
|
|
3042
3025
|
delete this.queues[tag];
|
|
3043
3026
|
delete this.runningCounts[tag];
|
|
3044
3027
|
}
|
|
@@ -3064,7 +3047,7 @@ var AsyncGraphLayer = class extends GraphLayer {
|
|
|
3064
3047
|
this.waitingNodes.push(node);
|
|
3065
3048
|
}
|
|
3066
3049
|
execute() {
|
|
3067
|
-
var _a
|
|
3050
|
+
var _a;
|
|
3068
3051
|
if (this.waitingNodes.length === 0) {
|
|
3069
3052
|
return {};
|
|
3070
3053
|
}
|
|
@@ -3076,9 +3059,9 @@ var AsyncGraphLayer = class extends GraphLayer {
|
|
|
3076
3059
|
break;
|
|
3077
3060
|
}
|
|
3078
3061
|
this.processingNodes.add(node);
|
|
3079
|
-
|
|
3062
|
+
result[_a = node.routineExecId] ?? (result[_a] = []);
|
|
3080
3063
|
let nextNodes;
|
|
3081
|
-
if (node
|
|
3064
|
+
if (node?.getConcurrency()) {
|
|
3082
3065
|
const tag = node.getTag();
|
|
3083
3066
|
ThrottleEngine.instance.setConcurrencyLimit(tag, node.getConcurrency());
|
|
3084
3067
|
nextNodes = ThrottleEngine.instance.throttle(
|
|
@@ -3543,9 +3526,8 @@ var Cadenza = class {
|
|
|
3543
3526
|
return new GraphRoutine(name, tasks, description, true);
|
|
3544
3527
|
}
|
|
3545
3528
|
static reset() {
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
(_b = this.registry) == null ? void 0 : _b.reset();
|
|
3529
|
+
this.broker?.reset();
|
|
3530
|
+
this.registry?.reset();
|
|
3549
3531
|
this.isBootstrapped = false;
|
|
3550
3532
|
}
|
|
3551
3533
|
};
|