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/trigger-workflows.mdx
+77-5Lines changed: 77 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,9 +6,81 @@ sidebar:
6
6
7
7
---
8
8
9
-
TODO
9
+
TODO - intro
10
+
11
+
## Workers API (Bindings)
12
+
13
+
You can interact with Workflows programmatically from any Worker script by creating a binding to a Workflow. A Worker can bind to multiple Workflows, including Workflows defined in other Workers projects (scripts) within your account.
14
+
15
+
You can interact with a Workflow:
16
+
17
+
* Directly over HTTP via the [`fetch`](/workers/runtime-apis/handlers/fetch/) handler
18
+
* From a [Queue consumer](/queues/configuration/javascript-apis/#consumer) inside a `queue` handler
19
+
* From a [Cron Trigger](/workers/configuration/cron-triggers/) inside a `scheduled` handler
20
+
* Within a [Durable Object](/durable-objects/).
21
+
22
+
:::note
23
+
24
+
New to Workflows? Start with the [Workflows tutorial](/workflows/get-started/guide/) to deploy your first Workflow and familiarize yourself with Workflows concepts.
25
+
26
+
:::
27
+
28
+
To bind to a Workflow from your Workers code, you need to define a [binding](/workers/wrangler/configuration/) to a specific Workflow. For example, to bind to the Workflow defined in the [get started guide](/workflows/get-started/guide/), you would configure a `wrangler.toml` with the below:
29
+
30
+
```toml title="wrangler.toml"
31
+
name = "workflows-tutorial"
32
+
main = "src/index.ts"
33
+
compatibility_date = "2024-10-15"
10
34
11
-
- HTTP via `fetch`
12
-
- Queue consumers
13
-
- Scheduled
14
-
- wrangler && REST API
35
+
[[workflows]]
36
+
# The name of the Workflow
37
+
name = "workflows-tutorial"
38
+
# The binding name, which must be a valid JavaScript variable name. This will
39
+
# be how you call (run) your Workflow from your other Workers handlers or
40
+
# scripts.
41
+
binding = "MY_WORKFLOW"
42
+
# script_name is required during for the beta.
43
+
# Must match the "name" of your Worker at the top of wrangler.toml
44
+
script_name = "workflows-tutorial"
45
+
# Must match the class defined in your code that extends the Workflow class
46
+
class_name = "MyWorkflow"
47
+
```
48
+
49
+
The `binding = "MY_WORKFLOW"` line defines the JavaScript variable that our Workflow methods are accessible on, including `create` (which triggers a new instance) or `get` (which returns the status of an existing instance).
The named Workflow definition, associated with a single Workers script.
7
+
8
+
- term: "instance"
9
+
general_definition: |-
10
+
A specific instance (running, paused, errored) of a Workflow. A Workflow can have a potentially infinite number of instances.
11
+
12
+
- term: "Step"
13
+
general_definition: |-
14
+
A step is self-contained, individually retriable component of a Workflow. Steps may emit (optional) state that allows a Workflow to persist and continue from that step, even if a Workflow fails due to a network or infrastructure issue. A Workflow can have one or more steps up to the [step limit](/workflows/reference/limits/).
15
+
16
+
- term: "Event"
17
+
general_definition: |-
18
+
The event that triggered the Workflow instance. A `WorkflowEvent` may contain optional parameters (data) that a Workflow can operate on.
19
+
20
+
- term: "Durable Execution"
21
+
general_definition: |-
22
+
"Durable Execution" is a programming model that allows applications to execute reliably, automatically persist state, retry, and be resistant to errors caused by API, network or even machine/infrastructure failures. Cloudflare Workflows provides a way to build and deploy applications that align with this model.
0 commit comments