Skip to content

Commit 25c4597

Browse files
committed
types
1 parent 3643022 commit 25c4597

File tree

2 files changed

+15
-32
lines changed

2 files changed

+15
-32
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Dynamic steps
3+
pcx_content_type: concept
4+
sidebar:
5+
order: 6
6+
7+
---
8+
9+
TODO - outline how to use TypeScript and

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

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,49 +51,23 @@ Open the `src/index.ts` file in your text editor. This file contains the followi
5151

5252
```ts title="src/index.ts"
5353
// Import the Workflow definition
54-
import { Workflow, WorkflowEvent, WorkflowStep } from "cloudflare:workflows"
54+
import { WorkflowEntrypoint, WorkflowEvent, WorkflowStep } from "cloudflare:workflows"
5555

5656
// Create your own class that implements a Workflow
57-
export class MyFirstWorkflow implements Workflow {
57+
export class MyWorkflow implements WorkflowEntrypoint {
5858
// Define a run() method
5959
async run(event: WorkflowEvent, step: WorkflowStep) {
6060
// Define one or more steps that optionally return state.
61-
const files = await step.do('my first step', async () => {
62-
// Fetch a list of files from $SOME_SERVICE
63-
return {
64-
inputParams: event,
65-
files: [
66-
'doc_7392_rev3.pdf',
67-
'report_x29_final.pdf',
68-
'memo_2024_05_12.pdf',
69-
'file_089_update.pdf',
70-
'proj_alpha_v2.pdf',
71-
'data_analysis_q2.pdf',
72-
'notes_meeting_52.pdf',
73-
'summary_fy24_draft.pdf',
74-
],
75-
};
76-
});
77-
78-
const apiResponse = await step.do('some other step', async () => {
79-
let resp = await fetch('https://api.cloudflare.com/client/v4/ips');
80-
return await resp.json<any>();
61+
const state = await step.do('my first step', async () => {
62+
return {}
8163
});
8264

8365
await step.sleep('wait on something', '1 minute');
8466

8567
await step.do(
8668
'make a call to write that could maybe, just might, fail',
87-
// {
88-
// retries: {
89-
// limit: 5,
90-
// delay: '5 second',
91-
// backoff: 'exponential',
92-
// },
93-
// timeout: '15 minutes',
94-
// },
9569
async () => {
96-
// Do stuff here, with access to my_value!
70+
// Do stuff here, with access to 'state' from the previous step
9771
if (Math.random() > 0.5) {
9872
throw new Error('API call to $STORAGE_SYSTEM failed');
9973
}
@@ -106,7 +80,7 @@ export class MyFirstWorkflow implements Workflow {
10680
A Workflow definition:
10781

10882
1. Defines a `run` method that contains the primary logic for your workflow.
109-
2. Has at least one or more calls to `step.run` that encapsulates the logic of your Workflow.
83+
2. Has at least one or more calls to `step.do` that encapsulates the logic of your Workflow.
11084
3. Allows steps to return (optional) state, allowing a Workflow to continue execution even if subsequent steps fail, without having to re-run all previous steps.
11185

11286
A single Worker application can contain multiple Workflow definitions, as long as each Workflow has a unique class name. This can be useful for code re-use or to define Workflows are related to each other conceptually.

0 commit comments

Comments
 (0)