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/get-started/cli-quick-start.mdx
+1-3Lines changed: 1 addition & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -89,9 +89,7 @@ Specifically:
89
89
90
90
## 2. Deploy a Workflow
91
91
92
-
Workflows are deployed via [`wrangler](/workers/wrangler/install-and-update/), which is installed when you first ran `npm create cloudflare`, above.
93
-
94
-
Deploying a Workflow is one
92
+
Workflows are deployed via [`wrangler](/workers/wrangler/install-and-update/), which is installed when you first ran `npm create cloudflare`, above. Workflows are Workers scripts, and deployed the same way.
# The binding name, which must be a valid JavaScript variable name. This will
154
154
# be how you call (run) your Workflow from your other Workers handlers or
155
155
# scripts.
@@ -158,7 +158,7 @@ binding = "MY_WORKFLOW"
158
158
# Must match the "name" of your Worker at the top of wrangler.toml
159
159
script_name = "workflows-tutorial"
160
160
# Must match the class defined in your code that extends the Workflow class
161
-
class_name = "MyFirstWorkflow"
161
+
class_name = "MyWorkflow"
162
162
```
163
163
164
164
:::note
@@ -178,27 +178,46 @@ We have a very basic Workflow definition, but now need to provide a way to call
178
178
3. A schedule via [Cron Trigger](/workers/configuration/cron-triggers/)
179
179
4. Via the [Workflows REST API](TODO) or [wrangler CLI](/workers/wrangler/commands/#workflows)
180
180
181
-
Return to the `src/index.ts` file we created in the previous step and add a `fetch` handler that _binds_ to our Workflow.
181
+
Return to the `src/index.ts` file we created in the previous step and add a `fetch` handler that _binds_ to our Workflow. This binding allows us to create new Workflow instances, fetch the status of an existing Workflow, pause and/or terminate a Workflow.
182
182
183
183
```ts title="src/index.ts"
184
+
// This can be in the same file as our Workflow definition
// If an ?instanceId=<id> query parameter is provided, fetch the status
192
+
// of an existing Workflow by its ID.
193
+
if (instanceId) {
194
+
let instance =awaitenv.MYWORKFLOW.get(id);
195
+
returnResponse.json({
196
+
status: awaitinstance.status(),
197
+
});
198
+
}
199
+
200
+
// Else, create a new instance of our Workflow, passing in any (optional) params
201
+
// and return the ID.
202
+
const newId =awaitcrypto.randomUUID();
203
+
let instance =awaitenv.MYWORKFLOW.create(newId, {});
204
+
returnResponse.json({
205
+
id: instance.id,
206
+
details: awaitinstance.status(),
207
+
});
208
+
187
209
returnResponse.json({ result });
188
210
},
189
211
};
190
212
```
191
213
192
-
TODO:
214
+
The code here exposes a HTTP endpoint that generates a random ID and runs the Workflow, returning the ID and the Workflow status. It also accepts an optional `instanceId` query parameter that retrieves the status of a Workflow instance by its ID.
193
215
194
-
* This is example exposes a HTTP endpoint and runs the Workflow without any parameters
195
-
* In a production application, you might choose to put authentication in front of your endpoint so that only authorized users can run a Workflow
196
-
* Alternatively, you could pass messages to a Workflow [from a Queue consumer](/queues/reference/how-queues-works/#consumers) in order to allow for long-running tasks.
216
+
:::note
197
217
218
+
In a production application, you might choose to put authentication in front of your endpoint so that only authorized users can run a Workflow. Alternatively, you could pass messages to a Workflow [from a Queue consumer](/queues/reference/how-queues-works/#consumers) in order to allow for long-running tasks.
0 commit comments