Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/content/docs/workflows/build/rules-of-workflows.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ export class MyWorkflow extends WorkflowEntrypoint {

Dynamically naming a step will prevent it from being cached, and cause the step to be re-run unnecessarily. Step names act as the "cache key" in your Workflow.

Note that, step names can be formed dynamically as long they are deterministic across steps and/or Workflow restarts.

```ts
export class MyWorkflow extends WorkflowEntrypoint {
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
Expand All @@ -243,7 +245,20 @@ export class MyWorkflow extends WorkflowEntrypoint {
// Return dynamic values in your state, or log them instead.
let state = await step.do("fetch user data from KV", async () => {
let userData = await env.KV.get(event.user)
console.log(`fetched at ${Date.now})
console.log(`fetched at ${Date.now}`)
return userData
})

// ✅ Good: steps that are dynamically named are constructed in a deterministic way.
// In this case, `catList` is a step output, which is stable, and `catList` is
// traversed in a deterministic fashion (no shuffles or random accesses) so,
// it's fine to dynamically name steps (e.g: create a step per list entry).
let catList = await step.do("get cat list from KV", async () => {
return await env.KV.get("cat-list")
})
for(const cat of carList) {
await step.do(`get cat: ${cat}`, async () => {
return await env.KV.get(cat)
})
}
```
Loading