@dudousxd/nestjs-durable-core 0.71.0 → 0.71.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.js CHANGED
@@ -3516,9 +3516,14 @@ var WorkflowEngine = class {
3516
3516
  async recoverIncomplete(nowMs = this.clock()) {
3517
3517
  if (this.draining) return [];
3518
3518
  const results = [];
3519
- for (const run of await this.store.listIncompleteRuns(this.namespace)) {
3520
- const acquired = await this.store.tryLockRun(run.id, this.instanceId, nowMs + this.leaseMs, nowMs);
3519
+ for (const listed of await this.store.listIncompleteRuns(this.namespace)) {
3520
+ const acquired = await this.store.tryLockRun(listed.id, this.instanceId, nowMs + this.leaseMs, nowMs);
3521
3521
  if (!acquired) continue;
3522
+ const run = await this.store.getRun(listed.id);
3523
+ if (!run || run.status !== "running" && run.status !== "cancelling") {
3524
+ await this.store.releaseRunLock(listed.id);
3525
+ continue;
3526
+ }
3522
3527
  if (run.status === "running") {
3523
3528
  const dispatched = await this.inFlightRemoteStep(run.id);
3524
3529
  if (dispatched) {
@@ -5378,16 +5383,16 @@ var WorkflowEngine = class {
5378
5383
  try {
5379
5384
  const output = await runInWorkflowCtx(ctx, () => fn(ctx, run.input));
5380
5385
  if (this.cancelRequested.has(run.id)) {
5381
- return this.compensateAndCancel(run, compensations, replay);
5386
+ return await this.compensateAndCancel(run, compensations, replay);
5382
5387
  }
5383
- return this.settleRun(run, {
5388
+ return await this.settleRun(run, {
5384
5389
  kind: "completed",
5385
5390
  output
5386
5391
  });
5387
5392
  } catch (err) {
5388
5393
  if (err instanceof ContinueAsNew) {
5389
5394
  if (this.cancelRequested.has(run.id)) {
5390
- return this.compensateAndCancel(run, compensations, replay);
5395
+ return await this.compensateAndCancel(run, compensations, replay);
5391
5396
  }
5392
5397
  await this.store.updateRun(run.id, {
5393
5398
  status: "completed",
@@ -5414,35 +5419,35 @@ var WorkflowEngine = class {
5414
5419
  }
5415
5420
  if (err instanceof WorkflowBlocked) {
5416
5421
  if (this.cancelRequested.has(run.id)) {
5417
- return this.compensateAndCancel(run, compensations, replay);
5422
+ return await this.compensateAndCancel(run, compensations, replay);
5418
5423
  }
5419
- return this.settleRun(run, {
5424
+ return await this.settleRun(run, {
5420
5425
  kind: "blocked",
5421
5426
  blocked: err.plan
5422
5427
  });
5423
5428
  }
5424
5429
  if (err instanceof WorkflowSuspended) {
5425
5430
  if (this.cancelRequested.has(run.id)) {
5426
- return this.compensateAndCancel(run, compensations, replay);
5431
+ return await this.compensateAndCancel(run, compensations, replay);
5427
5432
  }
5428
- return this.settleRun(run, {
5433
+ return await this.settleRun(run, {
5429
5434
  kind: "suspended",
5430
5435
  wakeAt: err.wakeAt
5431
5436
  });
5432
5437
  }
5433
5438
  if (this.cancelRequested.has(run.id)) {
5434
- return this.compensateAndCancel(run, compensations, replay);
5439
+ return await this.compensateAndCancel(run, compensations, replay);
5435
5440
  }
5436
5441
  const error2 = {
5437
5442
  message: err instanceof Error ? err.message : String(err),
5438
5443
  stack: err instanceof Error ? err.stack : void 0
5439
5444
  };
5440
5445
  const pending = await this.unwindCompensations(run, compensations, replay);
5441
- if (pending) return this.settleRun(run, {
5446
+ if (pending) return await this.settleRun(run, {
5442
5447
  kind: "suspended",
5443
5448
  wakeAt: pending.wakeAt
5444
5449
  });
5445
- return this.settleRun(run, {
5450
+ return await this.settleRun(run, {
5446
5451
  kind: "failed",
5447
5452
  error: error2
5448
5453
  });
@@ -5856,7 +5861,10 @@ var WorkflowEngine = class {
5856
5861
  }
5857
5862
  async callRemote(runId, seq, step, input, queue, transport, replay, admission, routing) {
5858
5863
  const group = stepGroup(step, routing?.namespace);
5859
- const existing = replay?.get(seq) ?? await this.store.getCheckpoint(runId, seq);
5864
+ let existing = replay?.get(seq) ?? await this.store.getCheckpoint(runId, seq);
5865
+ if (existing?.status === "pending" && replay?.has(seq)) {
5866
+ existing = await this.store.getCheckpoint(runId, seq) ?? existing;
5867
+ }
5860
5868
  if (existing && existing.name !== step.name) {
5861
5869
  throw new NonDeterminismError(runId, seq, step.name, existing.name);
5862
5870
  }