@dudousxd/nestjs-durable-core 0.76.0 → 0.76.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.cts CHANGED
@@ -3806,6 +3806,12 @@ declare class WorkflowEngine {
3806
3806
  * {@link redriveSettledSteps}).
3807
3807
  */
3808
3808
  private readonly awaitedRemoteSteps;
3809
+ /**
3810
+ * When THIS instance settled a remote step from its result, by `runId:seq`. That result's resume
3811
+ * runs here, and `execute` lets it into a lease this instance holds, so its wake is never the
3812
+ * dropped one {@link redriveSettledSteps} recovers. Pruned by age (see {@link noteSettledHere}).
3813
+ */
3814
+ private readonly settledHere;
3809
3815
  /** Flow-control admission backend for remote steps (see {@link registerQueue}). */
3810
3816
  private readonly admission;
3811
3817
  /** Runs on THIS instance blocked on admission, by queue — woken early on a freed-slot signal. */
@@ -4843,6 +4849,8 @@ declare class WorkflowEngine {
4843
4849
  * capable+compatible worker has appeared, else re-parks with a fresh `wakeAt` (design §7.5). */
4844
4850
  private dueBlockedRuns;
4845
4851
  private callRemote;
4852
+ /** Remember a step settled here, forgetting entries older than a lease so the map stays small. */
4853
+ private noteSettledHere;
4846
4854
  /** {@link StateStore.saveCheckpointIfPending}, or a plain save on a store without it. */
4847
4855
  private savePendingCheckpoint;
4848
4856
  /** Enqueue a remote step task to its worker group via the transport pool. Shared by the initial
package/dist/index.d.ts CHANGED
@@ -3806,6 +3806,12 @@ declare class WorkflowEngine {
3806
3806
  * {@link redriveSettledSteps}).
3807
3807
  */
3808
3808
  private readonly awaitedRemoteSteps;
3809
+ /**
3810
+ * When THIS instance settled a remote step from its result, by `runId:seq`. That result's resume
3811
+ * runs here, and `execute` lets it into a lease this instance holds, so its wake is never the
3812
+ * dropped one {@link redriveSettledSteps} recovers. Pruned by age (see {@link noteSettledHere}).
3813
+ */
3814
+ private readonly settledHere;
3809
3815
  /** Flow-control admission backend for remote steps (see {@link registerQueue}). */
3810
3816
  private readonly admission;
3811
3817
  /** Runs on THIS instance blocked on admission, by queue — woken early on a freed-slot signal. */
@@ -4843,6 +4849,8 @@ declare class WorkflowEngine {
4843
4849
  * capable+compatible worker has appeared, else re-parks with a fresh `wakeAt` (design §7.5). */
4844
4850
  private dueBlockedRuns;
4845
4851
  private callRemote;
4852
+ /** Remember a step settled here, forgetting entries older than a lease so the map stays small. */
4853
+ private noteSettledHere;
4846
4854
  /** {@link StateStore.saveCheckpointIfPending}, or a plain save on a store without it. */
4847
4855
  private savePendingCheckpoint;
4848
4856
  /** Enqueue a remote step task to its worker group via the transport pool. Shared by the initial
package/dist/index.js CHANGED
@@ -3704,6 +3704,12 @@ var WorkflowEngine = class {
3704
3704
  * {@link redriveSettledSteps}).
3705
3705
  */
3706
3706
  awaitedRemoteSteps = /* @__PURE__ */ new Map();
3707
+ /**
3708
+ * When THIS instance settled a remote step from its result, by `runId:seq`. That result's resume
3709
+ * runs here, and `execute` lets it into a lease this instance holds, so its wake is never the
3710
+ * dropped one {@link redriveSettledSteps} recovers. Pruned by age (see {@link noteSettledHere}).
3711
+ */
3712
+ settledHere = /* @__PURE__ */ new Map();
3707
3713
  /** Flow-control admission backend for remote steps (see {@link registerQueue}). */
3708
3714
  admission;
3709
3715
  /** Runs on THIS instance blocked on admission, by queue — woken early on a freed-slot signal. */
@@ -5131,6 +5137,16 @@ var WorkflowEngine = class {
5131
5137
  for (const seq of seqs) {
5132
5138
  const cp = await this.store.getCheckpoint(runId, seq);
5133
5139
  if (cp && (cp.status === "completed" || cp.status === "failed")) {
5140
+ if (this.settledHere.has(`${runId}:${seq}`)) return;
5141
+ const nowMs = this.clock();
5142
+ if (!await this.store.tryLockRun(runId, this.instanceId, nowMs + this.leaseMs, nowMs)) {
5143
+ return;
5144
+ }
5145
+ const run = await this.store.getRun(runId);
5146
+ if (run?.status !== "suspended") {
5147
+ await this.store.releaseRunLock(runId);
5148
+ return;
5149
+ }
5134
5150
  await this.resumeImplicit(runId);
5135
5151
  return;
5136
5152
  }
@@ -7227,6 +7243,15 @@ var WorkflowEngine = class {
7227
7243
  this.awaitedRemoteSteps.get(runId)?.add(seq);
7228
7244
  throw new WorkflowSuspended();
7229
7245
  }
7246
+ /** Remember a step settled here, forgetting entries older than a lease so the map stays small. */
7247
+ noteSettledHere(key) {
7248
+ const now = this.clock();
7249
+ this.settledHere.set(key, now);
7250
+ if (this.settledHere.size < 1024) return;
7251
+ for (const [k, at] of this.settledHere) {
7252
+ if (now - at > this.leaseMs) this.settledHere.delete(k);
7253
+ }
7254
+ }
7230
7255
  /** {@link StateStore.saveCheckpointIfPending}, or a plain save on a store without it. */
7231
7256
  async savePendingCheckpoint(checkpoint) {
7232
7257
  if (this.store.saveCheckpointIfPending) return this.store.saveCheckpointIfPending(checkpoint);
@@ -7273,6 +7298,7 @@ var WorkflowEngine = class {
7273
7298
  finishedAt
7274
7299
  });
7275
7300
  if (!claimed) return;
7301
+ this.noteSettledHere(`${result.runId}:${result.seq}`);
7276
7302
  this.emit({
7277
7303
  type: result.status === "completed" ? "step.completed" : "step.failed",
7278
7304
  runId: result.runId,