Skip to content

Commit e434d33

Browse files
authored
workflows: fix event.payload references (#19191)
1 parent 56f7b86 commit e434d33

File tree

5 files changed

+13
-15
lines changed

5 files changed

+13
-15
lines changed

src/content/docs/workflows/build/events-and-parameters.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export type WorkflowEvent<T> = {
7070
payload: T;
7171
// The timestamp that the Workflow was triggered
7272
timestamp: Date;
73-
// ID of the associated instance
73+
// ID of the current Workflow instance
7474
instanceId: string;
7575
};
7676
```

src/content/docs/workflows/build/rules-of-workflows.mdx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,17 @@ interface MyEvent {
219219
export class MyWorkflow extends WorkflowEntrypoint {
220220
async run(event: WorkflowEvent<MyEvent>, step: WorkflowStep) {
221221
// 🔴 Bad: Mutating the event
222-
// This will not be persisted across steps and `event.data` will
222+
// This will not be persisted across steps and `event.payload` will
223223
// take on its original value.
224224
await step.do("bad step that mutates the incoming event", async () => {
225-
let userData = await env.KV.get(event.user)
226-
event.data = userData
225+
let userData = await env.KV.get(event.payload.user)
226+
event.payload = userData
227227
})
228228

229229
// ✅ Good: persist data by returning it as state from your step
230230
// Use that state in subsequent steps
231231
let userData = await step.do("good step that returns state", async () => {
232-
return await env.KV.get(event.user)
232+
return await env.KV.get(event.payload.user)
233233
})
234234

235235
let someOtherData = await step.do("following step that uses that state", async () => {
@@ -252,14 +252,15 @@ export class MyWorkflow extends WorkflowEntrypoint {
252252
// 🔴 Bad: Naming the step non-deterministically prevents it from being cached
253253
// This will cause the step to be re-run if subsequent steps fail.
254254
await step.do(`step #1 running at: ${Date.now()}`, async () => {
255-
let userData = await env.KV.get(event.user)
256-
event.data = userData
255+
let userData = await env.KV.get(event.payload.user)
256+
// Do not mutate event.payload
257+
event.payload = userData
257258
})
258259

259260
// ✅ Good: give steps a deterministic name.
260261
// Return dynamic values in your state, or log them instead.
261262
let state = await step.do("fetch user data from KV", async () => {
262-
let userData = await env.KV.get(event.user)
263+
let userData = await env.KV.get(event.payload.user)
263264
console.log(`fetched at ${Date.now}`)
264265
return userData
265266
})

src/content/docs/workflows/build/sleeping-and-retrying.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ import { NonRetryableError } from 'cloudflare:workflows';
102102
export class MyWorkflow extends WorkflowEntrypoint<Env, Params> {
103103
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
104104
await step.do("some step", async () => {
105-
if !(event.data) {
106-
throw new NonRetryableError("event.data did not contain the expected payload")
105+
if !(event.payload.data) {
106+
throw new NonRetryableError("event.payload.data did not contain the expected payload")
107107
}
108108
})
109109
}

src/content/docs/workflows/get-started/cli-quick-start.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,11 @@ type Params = {
6666
export class MyWorkflow extends WorkflowEntrypoint<Env, Params> {
6767
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
6868
// Can access bindings on `this.env`
69-
// Can access params on `event.params`
69+
// Can access params on `event.payload`
7070

7171
const files = await step.do('my first step', async () => {
7272
// Fetch a list of files from $SOME_SERVICE
7373
return {
74-
inputParams: event,
7574
files: [
7675
'doc_7392_rev3.pdf',
7776
'report_x29_final.pdf',

src/content/docs/workflows/get-started/guide.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export class MyWorkflow extends WorkflowEntrypoint<Env, Params> {
6767
const files = await step.do('my first step', async () => {
6868
// Fetch a list of files from $SOME_SERVICE
6969
return {
70-
inputParams: event,
7170
files: [
7271
'doc_7392_rev3.pdf',
7372
'report_x29_final.pdf',
@@ -290,12 +289,11 @@ type Params = {
290289
export class MyWorkflow extends WorkflowEntrypoint<Env, Params> {
291290
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
292291
// Can access bindings on `this.env`
293-
// Can access params on `event.params`
292+
// Can access params on `event.payload`
294293

295294
const files = await step.do('my first step', async () => {
296295
// Fetch a list of files from $SOME_SERVICE
297296
return {
298-
inputParams: event,
299297
files: [
300298
'doc_7392_rev3.pdf',
301299
'report_x29_final.pdf',

0 commit comments

Comments
 (0)