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
let id =newURL(req.url).searchParams.get('instanceId');
119
-
120
-
// Get the status of an existing instance, if provided
121
-
if (id) {
122
-
let instance =awaitenv.MY_WORKFLOW.get(id);
123
-
returnResponse.json({
124
-
status: awaitinstance.status(),
125
-
});
126
-
}
127
-
128
-
// Spawn a new instance and return the ID and status
129
-
let instance =awaitenv.MY_WORKFLOW.create();
130
-
returnResponse.json({
131
-
id: instance.id,
132
-
details: awaitinstance.status(),
133
-
});
134
-
},
135
-
};
136
-
```
52
+
<GitHubCode
53
+
repo="cloudflare/workflows-starer"
54
+
file="src/index.ts"
55
+
commit="5b9c174fd1df3718e02544e19b8a83f3b93741ef"
56
+
lang="ts"
57
+
/>
137
58
138
59
Specifically, the code above:
139
60
@@ -172,15 +93,13 @@ You can [bind to a Workflow](/workers/runtime-apis/bindings/#what-is-a-binding)
172
93
173
94
To bind a Workflow to a Worker, you need to define a `[[workflows]]` binding in your `wrangler.toml` configuration:
174
95
175
-
```toml title="wrangler.toml"
176
-
[[workflows]]
177
-
# name of your workflow
178
-
name = "workflows-starter"
179
-
# binding name env.MY_WORKFLOW
180
-
binding = "MY_WORKFLOW"
181
-
# this is class that extends the Workflow class in src/index.ts
182
-
class_name = "MyWorkflow"
183
-
```
96
+
<GitHubCode
97
+
repo="cloudflare/workflows-starer"
98
+
file="wrangler.toml"
99
+
commit="5b9c174fd1df3718e02544e19b8a83f3b93741ef"
100
+
tag="workflows-binding-wrangler.toml"
101
+
lang="toml"
102
+
/>
184
103
185
104
You can then invoke the methods on this binding directly from your Worker script's `env` parameter. The `Workflow` type has methods for:
186
105
@@ -190,36 +109,13 @@ You can then invoke the methods on this binding directly from your Worker script
190
109
191
110
For example, the following Worker will fetch the status of an existing Workflow instance by ID (if supplied), else it will create a new Workflow instance and return its ID:
let id =newURL(req.url).searchParams.get('instanceId');
205
-
206
-
// Get the status of an existing instance, if provided
207
-
if (id) {
208
-
let instance =awaitenv.MY_WORKFLOW.get(id);
209
-
returnResponse.json({
210
-
status: awaitinstance.status(),
211
-
});
212
-
}
213
-
214
-
// Spawn a new instance and return the ID and status
215
-
let instance =awaitenv.MY_WORKFLOW.create();
216
-
returnResponse.json({
217
-
id: instance.id,
218
-
details: awaitinstance.status(),
219
-
});
220
-
},
221
-
};
222
-
```
112
+
<GitHubCode
113
+
repo="cloudflare/workflows-starer"
114
+
file="src/index.ts"
115
+
commit="5b9c174fd1df3718e02544e19b8a83f3b93741ef"
116
+
tag="workflows-fetch-handler"
117
+
lang="ts"
118
+
/>
223
119
224
120
Refer to the [triggering Workflows](/workflows/build/trigger-workflows/) documentation for how to trigger a Workflow from other Workers' handler functions.
0 commit comments