-
Notifications
You must be signed in to change notification settings - Fork 736
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/workers-observability-logs
- Loading branch information
Showing
39 changed files
with
864 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"wrangler": minor | ||
--- | ||
|
||
Fix wrangler pages deployment (list|tail) environment filtering. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@cloudflare/workflows-shared": minor | ||
"miniflare": minor | ||
--- | ||
|
||
Add proper engine persistance in .wrangler and fix multiple workflows in miniflare |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"wrangler": patch | ||
--- | ||
|
||
Rename `directory` to `projectRoot` and ensure it's relative to the `wrangler.toml`. This fixes a regression which meant that `.wrangler` temporary folders were inadvertently generated relative to `process.cwd()` rather than the location of the `wrangler.toml` file. It also renames `directory` to `projectRoot`, which affects the `unstable_startWorker() interface. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "my-workflow-multiple", | ||
"private": true, | ||
"scripts": { | ||
"deploy": "wrangler deploy", | ||
"start": "wrangler dev", | ||
"test:ci": "vitest" | ||
}, | ||
"devDependencies": { | ||
"@cloudflare/workers-types": "^4.20241106.0", | ||
"undici": "catalog:default", | ||
"wrangler": "workspace:*" | ||
}, | ||
"volta": { | ||
"extends": "../../package.json" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { | ||
WorkerEntrypoint, | ||
WorkflowEntrypoint, | ||
WorkflowEvent, | ||
WorkflowStep, | ||
} from "cloudflare:workers"; | ||
|
||
type Params = { | ||
name: string; | ||
}; | ||
|
||
export class Demo extends WorkflowEntrypoint<{}, Params> { | ||
async run(event: WorkflowEvent<Params>, step: WorkflowStep) { | ||
const { timestamp, payload } = event; | ||
|
||
await step.sleep("Wait", "1 second"); | ||
|
||
const result = await step.do("First step", async function () { | ||
return { | ||
output: "First step result", | ||
}; | ||
}); | ||
|
||
await step.sleep("Wait", "1 second"); | ||
|
||
const result2 = await step.do("Second step", async function () { | ||
return { | ||
output: "workflow1", | ||
}; | ||
}); | ||
|
||
return [result, result2, timestamp, payload, "workflow1"]; | ||
} | ||
} | ||
|
||
export class Demo2 extends WorkflowEntrypoint<{}, Params> { | ||
async run(event: WorkflowEvent<Params>, step: WorkflowStep) { | ||
const { timestamp, payload } = event; | ||
|
||
await step.sleep("Wait", "1 second"); | ||
|
||
const result = await step.do("First step", async function () { | ||
return { | ||
output: "First step result", | ||
}; | ||
}); | ||
|
||
await step.sleep("Wait", "1 second"); | ||
|
||
const result2 = await step.do("Second step", async function () { | ||
return { | ||
output: "workflow2", | ||
}; | ||
}); | ||
|
||
return [result, result2, timestamp, payload, "workflow2"]; | ||
} | ||
} | ||
|
||
type Env = { | ||
WORKFLOW: Workflow; | ||
WORKFLOW2: Workflow; | ||
}; | ||
|
||
export default class extends WorkerEntrypoint<Env> { | ||
async fetch(req: Request) { | ||
const url = new URL(req.url); | ||
const id = url.searchParams.get("id"); | ||
const workflowName = url.searchParams.get("workflowName"); | ||
|
||
if (url.pathname === "/favicon.ico") { | ||
return new Response(null, { status: 404 }); | ||
} | ||
let workflowToUse = | ||
workflowName == "2" ? this.env.WORKFLOW2 : this.env.WORKFLOW; | ||
|
||
let handle: WorkflowInstance; | ||
if (url.pathname === "/create") { | ||
if (id === null) { | ||
handle = await workflowToUse.create(); | ||
} else { | ||
handle = await workflowToUse.create({ id }); | ||
} | ||
} else { | ||
handle = await workflowToUse.get(id); | ||
} | ||
|
||
return Response.json({ status: await handle.status(), id: handle.id }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import { rm } from "fs/promises"; | ||
import { resolve } from "path"; | ||
import { fetch } from "undici"; | ||
import { afterAll, beforeAll, describe, it, vi } from "vitest"; | ||
import { runWranglerDev } from "../../shared/src/run-wrangler-long-lived"; | ||
|
||
describe("Workflows", () => { | ||
let ip: string, | ||
port: number, | ||
stop: (() => Promise<unknown>) | undefined, | ||
getOutput: () => string; | ||
|
||
beforeAll(async () => { | ||
// delete previous run contents because of persistence | ||
await rm(resolve(__dirname, "..") + "/.wrangler", { | ||
force: true, | ||
recursive: true, | ||
}); | ||
({ ip, port, stop, getOutput } = await runWranglerDev( | ||
resolve(__dirname, ".."), | ||
["--port=0", "--inspector-port=0"] | ||
)); | ||
}); | ||
|
||
afterAll(async () => { | ||
await stop?.(); | ||
}); | ||
|
||
async function fetchJson(url: string) { | ||
const response = await fetch(url, { | ||
headers: { | ||
"MF-Disable-Pretty-Error": "1", | ||
}, | ||
}); | ||
const text = await response.text(); | ||
|
||
try { | ||
return JSON.parse(text); | ||
} catch (err) { | ||
throw new Error(`Couldn't parse JSON:\n\n${text}`); | ||
} | ||
} | ||
|
||
it("creates two instances with same id in two different workflows", async ({ | ||
expect, | ||
}) => { | ||
const createResult = { | ||
id: "test", | ||
status: { | ||
status: "running", | ||
output: [], | ||
}, | ||
}; | ||
|
||
await Promise.all([ | ||
expect( | ||
fetchJson(`http://${ip}:${port}/create?workflowName=1&id=test`) | ||
).resolves.toStrictEqual(createResult), | ||
expect( | ||
fetchJson(`http://${ip}:${port}/create?workflowName=2&id=test`) | ||
).resolves.toStrictEqual(createResult), | ||
]); | ||
|
||
const firstResult = { | ||
id: "test", | ||
status: { | ||
status: "running", | ||
output: [{ output: "First step result" }], | ||
}, | ||
}; | ||
await Promise.all([ | ||
vi.waitFor( | ||
async () => { | ||
await expect( | ||
fetchJson(`http://${ip}:${port}/status?workflowName=1&id=test`) | ||
).resolves.toStrictEqual(firstResult); | ||
}, | ||
{ timeout: 5000 } | ||
), | ||
vi.waitFor( | ||
async () => { | ||
await expect( | ||
fetchJson(`http://${ip}:${port}/status?workflowName=2&id=test`) | ||
).resolves.toStrictEqual(firstResult); | ||
}, | ||
{ timeout: 5000 } | ||
), | ||
]); | ||
|
||
await Promise.all([ | ||
await vi.waitFor( | ||
async () => { | ||
await expect( | ||
fetchJson(`http://${ip}:${port}/status?workflowName=1&id=test`) | ||
).resolves.toStrictEqual({ | ||
id: "test", | ||
status: { | ||
status: "complete", | ||
output: [ | ||
{ output: "First step result" }, | ||
{ output: "workflow1" }, | ||
], | ||
}, | ||
}); | ||
}, | ||
{ timeout: 5000 } | ||
), | ||
await vi.waitFor( | ||
async () => { | ||
await expect( | ||
fetchJson(`http://${ip}:${port}/status?workflowName=2&id=test`) | ||
).resolves.toStrictEqual({ | ||
id: "test", | ||
status: { | ||
status: "complete", | ||
output: [ | ||
{ output: "First step result" }, | ||
{ output: "workflow2" }, | ||
], | ||
}, | ||
}); | ||
}, | ||
{ timeout: 5000 } | ||
), | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "@cloudflare/workers-tsconfig/tsconfig.json", | ||
"compilerOptions": { | ||
"types": ["node"] | ||
}, | ||
"include": ["**/*.ts", "../../../node-types.d.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2020", | ||
"module": "CommonJS", | ||
"lib": ["ES2020"], | ||
"types": ["@cloudflare/workers-types"], | ||
"moduleResolution": "node", | ||
"noEmit": true, | ||
"skipLibCheck": true | ||
}, | ||
"include": ["**/*.ts"], | ||
"exclude": ["tests"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { defineProject, mergeConfig } from "vitest/config"; | ||
import configShared from "../../vitest.shared"; | ||
|
||
export default mergeConfig( | ||
configShared, | ||
defineProject({ | ||
test: {}, | ||
}) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#:schema node_modules/wrangler/config-schema.json | ||
name = "my-workflow-demo" | ||
main = "src/index.ts" | ||
compatibility_date = "2024-10-22" | ||
|
||
[[workflows]] | ||
binding = "WORKFLOW" | ||
name = "my-workflow" | ||
class_name = "Demo" | ||
|
||
[[workflows]] | ||
binding = "WORKFLOW2" | ||
name = "my-workflow-2" | ||
class_name = "Demo2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.