@cadenza.io/core 3.16.4 → 3.17.1
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.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +55 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +55 -27
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1225,6 +1225,11 @@ var merge = createAssigner_default(function(object, source, srcIndex) {
|
|
|
1225
1225
|
});
|
|
1226
1226
|
var merge_default = merge;
|
|
1227
1227
|
|
|
1228
|
+
// src/utils/promise.ts
|
|
1229
|
+
function sleep(ms) {
|
|
1230
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1228
1233
|
// src/engine/SignalBroker.ts
|
|
1229
1234
|
var SignalBroker = class _SignalBroker {
|
|
1230
1235
|
constructor() {
|
|
@@ -1233,6 +1238,8 @@ var SignalBroker = class _SignalBroker {
|
|
|
1233
1238
|
this.debouncedEmitters = /* @__PURE__ */ new Map();
|
|
1234
1239
|
this.squashedEmitters = /* @__PURE__ */ new Map();
|
|
1235
1240
|
this.squashedContexts = /* @__PURE__ */ new Map();
|
|
1241
|
+
this.throttleEmitters = /* @__PURE__ */ new Map();
|
|
1242
|
+
this.throttleQueues = /* @__PURE__ */ new Map();
|
|
1236
1243
|
// TODO: Signals should be a class with a the observers, registered flag and other data.
|
|
1237
1244
|
this.signalObservers = /* @__PURE__ */ new Map();
|
|
1238
1245
|
this.emittedSignalsRegistry = /* @__PURE__ */ new Set();
|
|
@@ -1433,6 +1440,35 @@ var SignalBroker = class _SignalBroker {
|
|
|
1433
1440
|
}
|
|
1434
1441
|
debouncedEmitter(context);
|
|
1435
1442
|
}
|
|
1443
|
+
throttle(signal, context, options = { delayMs: 1e3 }) {
|
|
1444
|
+
let { groupId, delayMs = 300 } = options;
|
|
1445
|
+
if (!groupId) {
|
|
1446
|
+
groupId = signal;
|
|
1447
|
+
}
|
|
1448
|
+
if (!this.throttleQueues.has(groupId)) {
|
|
1449
|
+
this.throttleQueues.set(groupId, []);
|
|
1450
|
+
}
|
|
1451
|
+
const queue = this.throttleQueues.get(groupId);
|
|
1452
|
+
queue.push([signal, context]);
|
|
1453
|
+
if (!this.throttleEmitters.has(groupId)) {
|
|
1454
|
+
this.throttleEmitters.set(groupId, async () => {
|
|
1455
|
+
while (queue.length > 0) {
|
|
1456
|
+
let batchSize = options.throttleBatch ?? 1;
|
|
1457
|
+
if (batchSize > queue.length) {
|
|
1458
|
+
batchSize = queue.length;
|
|
1459
|
+
}
|
|
1460
|
+
for (let i = 0; i < batchSize; i++) {
|
|
1461
|
+
const [nextSignal, nextContext] = queue.shift();
|
|
1462
|
+
this.emit(nextSignal, nextContext);
|
|
1463
|
+
}
|
|
1464
|
+
await sleep(delayMs);
|
|
1465
|
+
}
|
|
1466
|
+
this.throttleEmitters.delete(groupId);
|
|
1467
|
+
this.throttleQueues.delete(groupId);
|
|
1468
|
+
});
|
|
1469
|
+
this.throttleEmitters.get(groupId)();
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1436
1472
|
/**
|
|
1437
1473
|
* Aggregates and debounces multiple events with the same identifier to minimize redundant operations.
|
|
1438
1474
|
*
|
|
@@ -1453,7 +1489,8 @@ var SignalBroker = class _SignalBroker {
|
|
|
1453
1489
|
this.squashedEmitters.set(
|
|
1454
1490
|
squashId,
|
|
1455
1491
|
debounce_default(() => {
|
|
1456
|
-
|
|
1492
|
+
options.squash = false;
|
|
1493
|
+
this.emit(signal, this.squashedContexts.get(squashId), options);
|
|
1457
1494
|
this.squashedEmitters.delete(squashId);
|
|
1458
1495
|
this.squashedContexts.delete(squashId);
|
|
1459
1496
|
}, delayMs ?? 300)
|
|
@@ -2057,11 +2094,6 @@ var SignalEmitter = class {
|
|
|
2057
2094
|
}
|
|
2058
2095
|
};
|
|
2059
2096
|
|
|
2060
|
-
// src/utils/promise.ts
|
|
2061
|
-
function sleep(ms) {
|
|
2062
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
2063
|
-
}
|
|
2064
|
-
|
|
2065
2097
|
// src/graph/execution/GraphNode.ts
|
|
2066
2098
|
var GraphNode = class _GraphNode extends SignalEmitter {
|
|
2067
2099
|
constructor(task, context, routineExecId, prevNodes = [], debug = false, verbose = false) {
|
|
@@ -2366,7 +2398,7 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
2366
2398
|
},
|
|
2367
2399
|
filter: { uuid: this.id }
|
|
2368
2400
|
},
|
|
2369
|
-
{ squash: true, squashId: this.id }
|
|
2401
|
+
{ squash: true, squashId: this.id, delayMs: 0 }
|
|
2370
2402
|
);
|
|
2371
2403
|
if (this.graphDone()) {
|
|
2372
2404
|
const context2 = this.context.getFullContext();
|
|
@@ -2388,7 +2420,7 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
2388
2420
|
},
|
|
2389
2421
|
filter: { uuid: this.routineExecId }
|
|
2390
2422
|
},
|
|
2391
|
-
{ squash: true, squashId: this.routineExecId }
|
|
2423
|
+
{ squash: true, squashId: this.routineExecId, delayMs: 0 }
|
|
2392
2424
|
);
|
|
2393
2425
|
}
|
|
2394
2426
|
return end;
|
|
@@ -3251,26 +3283,22 @@ var GraphRunner = class extends SignalEmitter {
|
|
|
3251
3283
|
}
|
|
3252
3284
|
});
|
|
3253
3285
|
}
|
|
3254
|
-
this.emitMetrics(
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
previousRoutineExecution: context.__localRoutineExecId ?? context.__metadata?.__routineExecId ?? null,
|
|
3266
|
-
created: formatTimestamp(Date.now())
|
|
3267
|
-
},
|
|
3268
|
-
__metadata: {
|
|
3269
|
-
__executionTraceId: executionTraceId
|
|
3270
|
-
}
|
|
3286
|
+
this.emitMetrics("meta.runner.added_tasks", {
|
|
3287
|
+
data: {
|
|
3288
|
+
uuid: routineExecId,
|
|
3289
|
+
name: routineName,
|
|
3290
|
+
routineVersion,
|
|
3291
|
+
isMeta,
|
|
3292
|
+
executionTraceId,
|
|
3293
|
+
context: ctx.getContext(),
|
|
3294
|
+
metaContext: ctx.getMetadata(),
|
|
3295
|
+
previousRoutineExecution: context.__localRoutineExecId ?? context.__metadata?.__routineExecId ?? null,
|
|
3296
|
+
created: formatTimestamp(Date.now())
|
|
3271
3297
|
},
|
|
3272
|
-
|
|
3273
|
-
|
|
3298
|
+
__metadata: {
|
|
3299
|
+
__executionTraceId: executionTraceId
|
|
3300
|
+
}
|
|
3301
|
+
});
|
|
3274
3302
|
}
|
|
3275
3303
|
allTasks.forEach(
|
|
3276
3304
|
(task) => this.currentRun.addNode(
|