Skip to content

Commit

Permalink
Workflows: fix getting a workflow when such workflow was not yet crea…
Browse files Browse the repository at this point in the history
…ted (#7520)

* fix getting a workflow when such workflow was not yet created

* Update .changeset/lovely-fireants-roll.md

Co-authored-by: Matt Silverlock <[email protected]>

* prettify

* cleanup

---------

Co-authored-by: Matt Silverlock <[email protected]>
  • Loading branch information
bruxodasilva and elithrar authored Dec 11, 2024
1 parent 6915a7a commit 805ad2b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/lovely-fireants-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudflare/workflows-shared": patch
---

Fixed a bug in local development where fetching a Workflow instance by ID would return a Workflow status, even if that instance did not exist. This only impacted the `get()` method on the Worker bindings.
2 changes: 1 addition & 1 deletion fixtures/import-npm/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions fixtures/workflow/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,15 @@ describe("Workflows", () => {
output: [],
});
});

it("fails getting a workflow without creating it first", async ({
expect,
}) => {
await expect(
fetchJson(`http://${ip}:${port}/status?workflowName=anotherTest`)
).resolves.toMatchObject({
message: "instance.not_found",
name: "Error",
});
});
});
4 changes: 4 additions & 0 deletions packages/workflows-shared/src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ export class Engine extends DurableObject<Env> {
_accountId: number,
_instanceId: string
): Promise<InstanceStatus> {
if (this.accountId === undefined) {
throw new Error("stub not initialized");
}

const res = await this.ctx.storage.get<InstanceStatus>(ENGINE_STATUS_KEY);

// NOTE(lduarte): if status don't exist, means that engine is running for the first time, so we assume queued
Expand Down

0 comments on commit 805ad2b

Please sign in to comment.