Skip to content

Commit 539c4ed

Browse files
committed
Merge branch 'ian/support-console-date'
2 parents dfdd9fc + f226715 commit 539c4ed

34 files changed

+1148
-1652
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ node_modules
1616
frontend/package.json
1717
# npm pack output
1818
*.tgz
19+
*.tsbuildinfo

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Changelog
22

3+
## 0.2.7 alpha
4+
5+
- Support for console logging & timing in workflows
6+
- Support for Date.now() in workflows
7+
- Batches the call to start steps
8+
- Adds the workflow name to the workpool execution for observability
9+
- Logs any error that shows up in the workflow body
10+
- Will call onComplete for Workflows with startAsync that fail
11+
on their first invocation.
12+
- Increases the max journal size from 1MB to 8MB
13+
- Adds the WorkflowId type to step.workflowId
14+
315
## 0.2.6
416

517
- Allow calling components directly from steps

CONTRIBUTING.md

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,37 @@
33
## Running locally
44

55
```sh
6-
npm i
7-
cd example
8-
npm i
9-
npx convex dev
6+
npm run setup
7+
npm run dev
108
```
119

1210
## Testing
1311

1412
```sh
15-
rm -rf dist/ && npm run build
13+
npm run clean
1614
npm run typecheck
17-
npm run test
18-
cd example
1915
npm run lint
20-
cd ..
16+
npm run test
2117
```
2218

2319
## Deploying
2420

2521
### Building a one-off package
2622

2723
```sh
28-
rm -rf dist/ && npm run build
24+
npm run clean
25+
npm run build
2926
npm pack
3027
```
3128

3229
### Deploying a new version
3330

3431
```sh
35-
# this will change the version and commit it (if you run it in the root directory)
36-
npm version patch
37-
npm publish --dry-run
38-
# sanity check files being included
39-
npm publish
40-
git push --tags
32+
npm run release
4133
```
4234

4335
#### Alpha release
4436

45-
The same as above, but it requires extra flags so the release is only installed with `@alpha`:
46-
4737
```sh
48-
npm version prerelease --preid alpha
49-
npm publish --tag alpha
38+
npm run alpha
5039
```

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Welcome to the world of Convex workflows.
2222
- Output from previous steps is available to pass to subsequent steps.
2323
- Run queries, mutations, and actions.
2424
- Specify retry behavior on a per-step basis, along with a default policy.
25-
- Specify how many workflows can run in parallel to manage load.
25+
- Specify how many workflow steps can run in parallel to manage load.
2626
- Cancel long-running workflows.
2727
- Clean up workflows after they're done.
2828

@@ -447,10 +447,8 @@ Here are a few limitations to keep in mind:
447447
mutation apply and limit the number and size of steps you can perform to 16MiB
448448
(including the workflow state overhead). See more about mutation limits here:
449449
https://docs.convex.dev/production/state/limits#transactions
450-
- `console.log()` isn't currently captured, so you may see duplicate log lines
451-
within your Convex dashboard if you log within the workflow definition.
452450
- We currently do not collect backtraces from within function calls from workflows.
453-
- If you need to use side effects like `fetch`, `Math.random()`, or `Date.now()`,
451+
- If you need to use side effects like `fetch` or use randomness,
454452
you'll need to do that in a step, not in the workflow definition.
455453
- If the implementation of the workflow meaningfully changes (steps added,
456454
removed, or reordered) then it will fail with a determinism violation.

convex.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"functions": "example/convex"
3+
}

example/.gitignore

Lines changed: 0 additions & 16 deletions
This file was deleted.

example/convex/_generated/api.d.ts

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -91,31 +91,32 @@ export declare const components: {
9191
};
9292
}
9393
>;
94-
startStep: FunctionReference<
94+
startSteps: FunctionReference<
9595
"mutation",
9696
"internal",
9797
{
9898
generationNumber: number;
99-
name: string;
100-
retry?:
101-
| boolean
102-
| { base: number; initialBackoffMs: number; maxAttempts: number };
103-
schedulerOptions?: { runAt?: number } | { runAfter?: number };
104-
step: {
105-
args: any;
106-
argsSize: number;
107-
completedAt?: number;
108-
functionType: "query" | "mutation" | "action";
109-
handle: string;
110-
inProgress: boolean;
111-
name: string;
112-
runResult?:
113-
| { kind: "success"; returnValue: any }
114-
| { error: string; kind: "failed" }
115-
| { kind: "canceled" };
116-
startedAt: number;
117-
workId?: string;
118-
};
99+
steps: Array<{
100+
retry?:
101+
| boolean
102+
| { base: number; initialBackoffMs: number; maxAttempts: number };
103+
schedulerOptions?: { runAt?: number } | { runAfter?: number };
104+
step: {
105+
args: any;
106+
argsSize: number;
107+
completedAt?: number;
108+
functionType: "query" | "mutation" | "action";
109+
handle: string;
110+
inProgress: boolean;
111+
name: string;
112+
runResult?:
113+
| { kind: "success"; returnValue: any }
114+
| { error: string; kind: "failed" }
115+
| { kind: "canceled" };
116+
startedAt: number;
117+
workId?: string;
118+
};
119+
}>;
119120
workflowId: string;
120121
workpoolOptions?: {
121122
defaultRetryBehavior?: {
@@ -128,7 +129,7 @@ export declare const components: {
128129
retryActionsByDefault?: boolean;
129130
};
130131
},
131-
{
132+
Array<{
132133
_creationTime: number;
133134
_id: string;
134135
step: {
@@ -148,7 +149,7 @@ export declare const components: {
148149
};
149150
stepNumber: number;
150151
workflowId: string;
151-
}
152+
}>
152153
>;
153154
};
154155
workflow: {

example/convex/example.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@ export const exampleWorkflow = workflow.define({
2828
windSpeed: number;
2929
windGust: number;
3030
}> => {
31+
console.time("overall");
32+
console.time("geocoding");
3133
// Run in parallel!
3234
const [{ latitude, longitude, name }, weather2] = await Promise.all([
3335
step.runAction(internal.example.getGeocoding, args, { runAfter: 100 }),
3436
step.runAction(internal.example.getGeocoding, args, { retry: true }),
3537
]);
3638
console.log("Is geocoding is consistent?", latitude === weather2.latitude);
37-
39+
console.timeLog("geocoding", name);
40+
console.time("weather");
3841
const weather = await step.runAction(internal.example.getWeather, {
3942
latitude,
4043
longitude,
@@ -45,6 +48,12 @@ export const exampleWorkflow = workflow.define({
4548
console.log(
4649
`Weather in ${name}: ${farenheit.toFixed(1)}°F (${temperature}°C), ${windSpeed} km/h, ${windGust} km/h`,
4750
);
51+
console.timeLog("weather", temperature);
52+
await step.runMutation(internal.example.updateFlow, {
53+
workflowId: step.workflowId,
54+
out: { name, celsius, farenheit, windSpeed, windGust },
55+
});
56+
console.timeEnd("overall");
4857
return { name, celsius, farenheit, windSpeed, windGust };
4958
},
5059
workpoolOptions: {
@@ -109,7 +118,8 @@ export const flowCompleted = internalMutation({
109118
await ctx.db.patch(flow._id, {
110119
out: args.result,
111120
});
112-
await workflow.cleanup(ctx, args.workflowId);
121+
// To delete the workflow data after it completes:
122+
// await workflow.cleanup(ctx, args.workflowId);
113123
},
114124
});
115125

example/convex/setup.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import schema from "./schema";
55
export const modules = import.meta.glob("./**/*.*s");
66

77
// Sorry about everything
8-
import componentSchema from "../node_modules/@convex-dev/workflow/src/component/schema";
8+
import componentSchema from "../../node_modules/@convex-dev/workflow/src/component/schema";
99
export { componentSchema };
1010
export const componentModules = import.meta.glob(
11-
"../node_modules/@convex-dev/workflow/src/component/**/*.ts",
11+
"../../node_modules/@convex-dev/workflow/src/component/**/*.ts",
1212
);
1313

1414
export function initConvexTest() {

0 commit comments

Comments
 (0)