File tree Expand file tree Collapse file tree 3 files changed +48
-2
lines changed
src/content/docs/workflows/build Expand file tree Collapse file tree 3 files changed +48
-2
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,8 @@ Store state durably by returning it from your `step.do` callbacks.
3030
3131:::
3232
33+ <TypeScriptExample >
34+
3335``` ts
3436export default {
3537 async fetch(req : Request , env : Env ) {
@@ -52,6 +54,8 @@ export default {
5254};
5355```
5456
57+ </TypeScriptExample >
58+
5559To pass parameters via the ` wrangler ` command-line interface, pass a JSON string as the second parameter to the ` workflows trigger ` sub-command:
5660
5761``` sh
@@ -63,7 +67,23 @@ npx wrangler@latest workflows trigger workflows-starter '{"some":"data"}'
6367
6468### Wait for events
6569
66- TODO -
70+ A running Workflow can wait for an event (or events) by calling ` step.waitForEvent ` .
71+
72+ <TypeScriptExample >
73+
74+ ``` ts
75+ export class MyWorkflow extends WorkflowEntrypoint <Env , Params > {
76+ async run(event : WorkflowEvent <Params >, step : WorkflowStep ) {
77+ // TODO
78+ //
79+ // TODO
80+ }
81+ }
82+ ```
83+
84+ </TypeScriptExample >
85+
86+ Visit the [ guide on sending data to Workflows] to learn about how to pass event data to a running Workflow, including via HTTP (webhooks) and/or Workers bindings.
6787
6888## TypeScript and type parameters
6989
Original file line number Diff line number Diff line change 11---
2- title : Human in the loop
2+ title : Send data to running Workflows
33pcx_content_type : concept
44sidebar :
55 order : 7
66---
77
88import { WranglerConfig , TypeScriptExample } from " ~/components" ;
99
10+ ###
Original file line number Diff line number Diff line change @@ -404,6 +404,31 @@ Terminate a Workflow instance.
404404
405405* <code >terminate(): Promise< ; void> ; </code >
406406
407+ ### sendEvent
408+
409+ [ Send an event] ( ) to a running Workflow instance.
410+
411+ * <code >sendEvent(): Promise< ; void> ; </code >
412+
413+ * ` options ` - the event ` type ` and ` payload ` to send to the Workflow instance. The ` type ` must match the ` type ` in
414+
415+ Return ` void ` on success; throws an exception if the Workflow is not running or is an errored state.
416+
417+ <TypeScriptExample >
418+
419+ ``` ts
420+ export class MyWorkflow extends WorkflowEntrypoint <Env , Params > {
421+ async run(event : WorkflowEvent <Params >, step : WorkflowStep ) {
422+ // TODO
423+ //
424+ // TODO
425+ }
426+ }
427+ ```
428+
429+ </TypeScriptExample >
430+
431+
407432### InstanceStatus
408433
409434Details the status of a Workflow instance.
You can’t perform that action at this time.
0 commit comments