@dudousxd/nestjs-durable-core 0.75.0 → 0.75.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.cjs +29 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +29 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -3801,6 +3801,8 @@ declare class WorkflowEngine {
|
|
|
3801
3801
|
private draining;
|
|
3802
3802
|
/** Wait already spent on this shutdown before `drain()` (see `beginDrain`). */
|
|
3803
3803
|
private drainSpentMs;
|
|
3804
|
+
/** Re-arms the deadline of every `drain()` currently waiting, when more wait is reported. */
|
|
3805
|
+
private readonly drainRearms;
|
|
3804
3806
|
constructor(deps: WorkflowEngineDeps);
|
|
3805
3807
|
/**
|
|
3806
3808
|
* Register a **durable entity** (a virtual object): a keyed actor whose `handlers` run **serialized
|
package/dist/index.d.ts
CHANGED
|
@@ -3801,6 +3801,8 @@ declare class WorkflowEngine {
|
|
|
3801
3801
|
private draining;
|
|
3802
3802
|
/** Wait already spent on this shutdown before `drain()` (see `beginDrain`). */
|
|
3803
3803
|
private drainSpentMs;
|
|
3804
|
+
/** Re-arms the deadline of every `drain()` currently waiting, when more wait is reported. */
|
|
3805
|
+
private readonly drainRearms;
|
|
3804
3806
|
constructor(deps: WorkflowEngineDeps);
|
|
3805
3807
|
/**
|
|
3806
3808
|
* Register a **durable entity** (a virtual object): a keyed actor whose `handlers` run **serialized
|
package/dist/index.js
CHANGED
|
@@ -3709,6 +3709,8 @@ var WorkflowEngine = class {
|
|
|
3709
3709
|
draining = false;
|
|
3710
3710
|
/** Wait already spent on this shutdown before `drain()` (see `beginDrain`). */
|
|
3711
3711
|
drainSpentMs = 0;
|
|
3712
|
+
/** Re-arms the deadline of every `drain()` currently waiting, when more wait is reported. */
|
|
3713
|
+
drainRearms = /* @__PURE__ */ new Set();
|
|
3712
3714
|
constructor(deps) {
|
|
3713
3715
|
this.store = deps.store;
|
|
3714
3716
|
this.pool = new TransportPool(deps.transports ?? (deps.transport ? [
|
|
@@ -4394,7 +4396,10 @@ var WorkflowEngine = class {
|
|
|
4394
4396
|
*/
|
|
4395
4397
|
beginDrain(spentMs = 0) {
|
|
4396
4398
|
this.draining = true;
|
|
4397
|
-
|
|
4399
|
+
if (Number.isFinite(spentMs) && spentMs > 0) {
|
|
4400
|
+
this.drainSpentMs += spentMs;
|
|
4401
|
+
for (const rearm of this.drainRearms) rearm();
|
|
4402
|
+
}
|
|
4398
4403
|
}
|
|
4399
4404
|
/**
|
|
4400
4405
|
* Graceful shutdown: stop picking up new runs (recovery/timer become no-ops) and wait for
|
|
@@ -4407,18 +4412,32 @@ var WorkflowEngine = class {
|
|
|
4407
4412
|
*/
|
|
4408
4413
|
async drain(timeoutMs = 1e4) {
|
|
4409
4414
|
this.beginDrain();
|
|
4410
|
-
const budget = Math.max(0, timeoutMs - this.drainSpentMs);
|
|
4411
4415
|
if (this.inflight.size === 0) return;
|
|
4416
|
+
const start = Date.now();
|
|
4417
|
+
let rearm = /* @__PURE__ */ __name(() => {
|
|
4418
|
+
}, "rearm");
|
|
4419
|
+
let timeout;
|
|
4412
4420
|
const timer = new Promise((resolve) => {
|
|
4413
|
-
|
|
4414
|
-
|
|
4421
|
+
rearm = /* @__PURE__ */ __name(() => {
|
|
4422
|
+
clearTimeout(timeout);
|
|
4423
|
+
const remaining = Math.max(0, start + timeoutMs - this.drainSpentMs - Date.now());
|
|
4424
|
+
timeout = setTimeout(resolve, remaining);
|
|
4425
|
+
timeout.unref?.();
|
|
4426
|
+
}, "rearm");
|
|
4427
|
+
rearm();
|
|
4415
4428
|
});
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4429
|
+
this.drainRearms.add(rearm);
|
|
4430
|
+
try {
|
|
4431
|
+
await Promise.race([
|
|
4432
|
+
Promise.allSettled([
|
|
4433
|
+
...this.inflight
|
|
4434
|
+
]),
|
|
4435
|
+
timer
|
|
4436
|
+
]);
|
|
4437
|
+
} finally {
|
|
4438
|
+
this.drainRearms.delete(rearm);
|
|
4439
|
+
clearTimeout(timeout);
|
|
4440
|
+
}
|
|
4422
4441
|
}
|
|
4423
4442
|
/**
|
|
4424
4443
|
* Cancel in-flight runs that have outlived their workflow's `executionTimeout`. Call it from the
|