You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/workflows/build/workers-api.mdx
+79-27Lines changed: 79 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,57 +6,109 @@ sidebar:
6
6
7
7
---
8
8
9
-
TODO
9
+
Workflows exposes a API directly to your Workers scripts via the [bindings](/workers/runtime-apis/bindings/#what-is-a-binding) concept. Bindings allow you to securely call a Workflow without having to manage API keys or clients.
10
10
11
-
## Binding
11
+
This guide details the Workflows API within Cloudflare Workers, including methods, types and usage examples.
12
12
13
-
TODO
13
+
## Bind to a Workflow
14
14
15
-
## Interact with Workflows
15
+
:::note[Workflows beta]
16
16
17
-
* Running a Workflow with the `run()` method
18
-
*`StepConfig`
19
-
*`NonRetriableError`
20
-
* TODO on TypeScript type params
17
+
Workflows currently requires you to bind to a Workflow via `wrangler.toml` and does not yet support bindings via the Workers dashboard.
18
+
19
+
:::
20
+
21
+
You can bind to a Workflow by defining a `[[workflows]]` binding within your `wrangler.toml` configuration.
22
+
23
+
For example, to bind to a Workflow called `workflows-starter` and to make it available on the `MY_WORKFLOW` variable to your Worker script, you would configure the following fields within the `[[workflows]]` binding definition:
24
+
25
+
```toml title="wrangler.toml"
26
+
#:schema node_modules/wrangler/config-schema.json
27
+
name = "workflows-starter"
28
+
main = "src/index.ts"
29
+
compatibility_date = "2024-10-16"
30
+
31
+
[[workflows]]
32
+
# name of your workflow
33
+
name = "workflows-starter"
34
+
# binding name env.MYWORKFLOW
35
+
binding = "MY_WORKFLOW"
36
+
# this is class that extends the Workflow class in src/index.ts
37
+
class_name = "MyWorkflow"
38
+
# script_name is required during for the beta.
39
+
# Must match the "name" of your Worker at the top of wrangler.toml
*`event` - the event passed to the Workflow, including an optional `payload` containing data (parameters)
48
+
*`step` - the `WorkflowStep` type that provides the step methods for your Workflow
49
+
50
+
The `WorkflowEvent` type accepts an optional [type parameter](https://www.typescriptlang.org/docs/handbook/2/generics.html#working-with-generic-type-variables) that allows you to provide a type for the `payload` property within the `WorkflowEvent`.
51
+
52
+
Refer to the [events and parameters](/workflows/build/events-and-parameters/) documentation for how to handle events within yur Workflow code.
* <code>step.sleepUntil(name: string, timestamp: Date | number): Promise<void></code>
52
88
53
-
* TODO -
89
+
*`name` - the name of the step.
90
+
*`timestamp` - a JavaScript `Date` object or seconds from the Unix epoch to sleep the Workflow instance until.
91
+
92
+
## WorkflowStepConfig
93
+
94
+
```ts
95
+
exporttypeWorkflowStepConfig= {
96
+
retries?: {
97
+
limit:number;
98
+
delay:string|number;
99
+
backoff?:WorkflowBackoff;
100
+
};
101
+
timeout?:string|number;
102
+
};
103
+
```
54
104
55
-
TODO - show an example
105
+
* A `WorkflowStepConfig` is an optional argument to the `do` method of a `WorkflowStep` and defines properties that allow you to configure the retry behaviour of that step.
56
106
107
+
Refer to the [documentation on sleeping and retrying](/workflows/build/sleeping-and-retrying/) to learn more about how how Workflows are retried.
57
108
58
-
## StepConfig
109
+
## NonRetryableError
59
110
60
-
TODO
111
+
* <code>throw new NonRetryableError(message: <Typetext='string' />, name <Typetext='string' /> <MetaInfotext='optional' />)</code>: <Typetext='NonRetryableError' />
61
112
62
-
## NonRetriableError
113
+
* Throws an error that forces the current Workflow instance to fail and not be retried.
114
+
* Refer to the [documentation on sleeping and retrying](/workflows/build/sleeping-and-retrying/) to learn more about how how Workflows are retried.
0 commit comments