Skip to content

Commit 7b5ec8b

Browse files
committed
readme troubleshooting
1 parent 35076d7 commit 7b5ec8b

File tree

1 file changed

+52
-7
lines changed

1 file changed

+52
-7
lines changed

README.md

+52-7
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const exampleWorkflow = workflow.define({
3636
args: {
3737
storageId: v.id("_storage"),
3838
},
39-
handler: async (step, args) => {
39+
handler: async (step, args): Promise<number[]> => {
4040
const transcription = await step.runAction(
4141
internal.index.computeTranscription,
4242
{ storageId: args.storageId },
@@ -48,7 +48,7 @@ export const exampleWorkflow = workflow.define({
4848
// Run this a month after the transcription is computed.
4949
{ runAfter: 30 * 24 * 60 * 60 * 1000 },
5050
);
51-
console.log(embedding);
51+
return embedding;
5252
},
5353
});
5454
```
@@ -101,6 +101,9 @@ is designed to feel like a Convex action but with a few restrictions:
101101
restrictions over time by implementing `Math.random()`, `Date.now()`, and
102102
`fetch` within our workflow environment.
103103

104+
Note: To help avoid type cycles, always annotate the return type of the `handler`
105+
with the return type of the workflow.
106+
104107
```ts
105108
export const exampleWorkflow = workflow.define({
106109
args: { name: v.string() },
@@ -211,7 +214,7 @@ a `Promise.all()` call.
211214
```ts
212215
export const exampleWorkflow = workflow.define({
213216
args: { name: v.string() },
214-
handler: async (step, args) => {
217+
handler: async (step, args): Promise<void> => {
215218
const [result1, result2] = await Promise.all([
216219
step.runAction(internal.example.myAction, args),
217220
step.runAction(internal.example.myAction, args),
@@ -263,7 +266,7 @@ const workflow = new WorkflowManager(components.workflow, {
263266

264267
export const exampleWorkflow = workflow.define({
265268
args: { name: v.string() },
266-
handler: async (step, args) => {
269+
handler: async (step, args): Promise<void> => {
267270
// Uses default retry behavior & retryActionsByDefault
268271
await step.runAction(internal.example.myAction, args);
269272
// Retries will be attempted with the default behavior
@@ -372,17 +375,59 @@ export const kickoffWorkflow = action({
372375

373376
You can specify a custom name for a step by passing a `name` option to the step.
374377

378+
This allows the events emitted to your logs to be more descriptive.
379+
By default it uses the `file/folder:function` name.
380+
375381
```ts
376382
export const exampleWorkflow = workflow.define({
377383
args: { name: v.string() },
378-
handler: async (step, args) => {
384+
handler: async (step, args): Promise<void> => {
379385
await step.runAction(internal.example.myAction, args, { name: "FOO" });
380386
},
381387
});
382388
```
383389

384-
This allows the events emitted to your logs to be more descriptive.
385-
By default it uses the `file/folder:function` name.
390+
## Tips and troubleshooting
391+
392+
### Circular dependencies
393+
394+
Having the return value of workflows depend on other Convex functions can lead to circular dependencies due to the
395+
`internal.foo.bar` way of specifying functions. The way to fix this is to explicitly type the return value of the
396+
workflow. When in doubt, add return types to more `handler` functions, like this:
397+
398+
```ts
399+
export const supportAgentWorkflow = workflow.define({
400+
args: { prompt: v.string(), userId: v.string(), threadId: v.string() },
401+
+ handler: async (step, { prompt, userId, threadId }): Promise<string> => {
402+
// ...
403+
},
404+
});
405+
406+
// And regular functions too:
407+
export const myFunction = action({
408+
args: { prompt: v.string() },
409+
+ handler: async (ctx, { prompt }): Promise<string> => {
410+
// ...
411+
},
412+
});
413+
```
414+
415+
### More concise workflows
416+
417+
To avoid the noise of `internal.foo.*` syntax, you can use a variable.
418+
For instance, if you define all your steps in `convex/steps.ts`, you can do this:
419+
420+
```ts
421+
const s = internal.steps;
422+
423+
export const myWorkflow = workflow.define({
424+
args: { prompt: v.string() },
425+
handler: async (step, args): Promise<string> => {
426+
+ const result = await step.runAction(s.myAction, args);
427+
return result;
428+
},
429+
});
430+
```
386431

387432
## Limitations
388433

0 commit comments

Comments
 (0)