Skip to content

Commit b680714

Browse files
committed
Address review comments
1 parent 12f3560 commit b680714

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

packages/miniflare/src/workers/workflows/wrapped-binding.worker.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,43 +74,37 @@ class InstanceImpl implements WorkflowInstance {
7474
}
7575

7676
public async pause(): Promise<void> {
77-
const instance = await this.getInstance();
77+
using instance = await this.getInstance();
7878
await instance.pause();
79-
instance[Symbol.dispose]();
8079
}
8180

8281
public async resume(): Promise<void> {
83-
const instance = await this.getInstance();
82+
using instance = await this.getInstance();
8483
await instance.resume();
85-
instance[Symbol.dispose]();
8684
}
8785

8886
public async terminate(): Promise<void> {
89-
const instance = await this.getInstance();
87+
using instance = await this.getInstance();
9088
await instance.terminate();
91-
instance[Symbol.dispose]();
9289
}
9390

9491
public async restart(): Promise<void> {
95-
const instance = await this.getInstance();
92+
using instance = await this.getInstance();
9693
await instance.restart();
97-
instance[Symbol.dispose]();
9894
}
9995

10096
public async status(): Promise<InstanceStatus> {
101-
const instance = await this.getInstance();
97+
using instance = await this.getInstance();
10298
using res = (await instance.status()) as InstanceStatus & Disposable;
103-
instance[Symbol.dispose]();
10499
return structuredClone(res);
105100
}
106101

107102
public async sendEvent(args: {
108103
payload: unknown;
109104
type: string;
110105
}): Promise<void> {
111-
const instance = await this.getInstance();
106+
using instance = await this.getInstance();
112107
await instance.sendEvent(args);
113-
instance[Symbol.dispose]();
114108
}
115109
}
116110

packages/workflows-shared/src/engine.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { computeHash } from "./lib/cache";
1212
import {
1313
ABORT_REASONS,
1414
createWorkflowError,
15+
isAbortError,
1516
isUserTriggeredPause,
1617
WorkflowFatalError,
1718
} from "./lib/errors";
@@ -646,15 +647,22 @@ export class Engine extends DurableObject<Env> {
646647
InstanceStatus.WaitingForPause
647648
);
648649

649-
void this.timeoutHandler.waitUntilNothingIsRunning("pause", async () => {
650-
await this.ctx.storage.put(PAUSE_DATETIME, new Date());
651-
await this.setStatus(
652-
metadata.accountId,
653-
metadata.instance.id,
654-
InstanceStatus.Paused
655-
);
656-
await this.abort(ABORT_REASONS.USER_PAUSE);
657-
});
650+
void this.timeoutHandler
651+
.waitUntilNothingIsRunning("pause", async () => {
652+
await this.ctx.storage.put(PAUSE_DATETIME, new Date());
653+
await this.setStatus(
654+
metadata.accountId,
655+
metadata.instance.id,
656+
InstanceStatus.Paused
657+
);
658+
await this.abort(ABORT_REASONS.USER_PAUSE);
659+
})
660+
.catch((e) => {
661+
// Expected: abort rejects the promise chain when it kills the DO
662+
if (!isAbortError(e)) {
663+
throw e;
664+
}
665+
});
658666
}
659667

660668
async userTriggeredRestart() {
@@ -808,6 +816,7 @@ export class Engine extends DurableObject<Env> {
808816
InstanceStatus.Errored, // TODO (WOR-85): Remove this once upgrade story is done
809817
InstanceStatus.Terminated,
810818
InstanceStatus.Complete,
819+
InstanceStatus.Paused,
811820
].includes(status)
812821
) {
813822
return;

0 commit comments

Comments
 (0)