Skip to content

Commit 5e5eca0

Browse files
committed
glossary
1 parent 95b5be0 commit 5e5eca0

File tree

3 files changed

+112
-5
lines changed

3 files changed

+112
-5
lines changed

src/content/docs/workflows/build/trigger-workflows.mdx

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,81 @@ sidebar:
66

77
---
88

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"
1034

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).
50+
51+
```ts title="src/index.ts"
52+
interface Env {
53+
MY_WORKFLOW: Workflow;
54+
}
55+
56+
export default {
57+
async fetch(req: Request, env: Env) {
58+
//
59+
const instanceId = new URL(req.url).searchParams.get("instanceId")
60+
61+
// If an ?instanceId=<id> query parameter is provided, fetch the status
62+
// of an existing Workflow by its ID.
63+
if (instanceId) {
64+
let instance = await env.MY_WORKFLOW.get(id);
65+
return Response.json({
66+
status: await instance.status(),
67+
});
68+
}
69+
70+
// Else, create a new instance of our Workflow, passing in any (optional) params
71+
// and return the ID.
72+
const newId = await crypto.randomUUID();
73+
let instance = await env.MY_WORKFLOW.create(newId, {});
74+
return Response.json({
75+
id: instance.id,
76+
details: await instance.status(),
77+
});
78+
79+
return Response.json({ result });
80+
},
81+
};
82+
```
83+
84+
## REST API (HTTP)
85+
86+
TODO
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: Glossary
3+
pcx_content_type: glossary
4+
sidebar:
5+
order: 10
6+
7+
---
8+
9+
import { Glossary } from "~/components"
10+
11+
Review the definitions for terms used across Cloudflare's Workflows documentation.
12+
13+
<Glossary product="workflows" />
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
productName: Workflows
3+
entries:
4+
- term: "Workflow"
5+
general_definition: |-
6+
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

Comments
 (0)