@convex-dev/workpool 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +33 -7
- package/dist/client/index.js.map +1 -1
- package/dist/component/_generated/server.d.ts.map +1 -1
- package/dist/component/complete.d.ts.map +1 -1
- package/dist/component/complete.js +61 -5
- package/dist/component/complete.js.map +1 -1
- package/dist/component/config.js.map +1 -1
- package/dist/component/crons.d.ts +1 -1
- package/dist/component/crons.d.ts.map +1 -1
- package/dist/component/crons.js +2 -2
- package/dist/component/crons.js.map +1 -1
- package/dist/component/danger.d.ts +0 -2
- package/dist/component/danger.d.ts.map +1 -1
- package/dist/component/danger.js +63 -35
- package/dist/component/danger.js.map +1 -1
- package/dist/component/lib.d.ts +1 -1
- package/dist/component/lib.d.ts.map +1 -1
- package/dist/component/lib.js +43 -3
- package/dist/component/lib.js.map +1 -1
- package/dist/component/loop.js +2 -2
- package/dist/component/loop.js.map +1 -1
- package/dist/component/recovery.js +7 -7
- package/dist/component/recovery.js.map +1 -1
- package/dist/component/schema.d.ts +14 -3
- package/dist/component/schema.d.ts.map +1 -1
- package/dist/component/schema.js +9 -1
- package/dist/component/schema.js.map +1 -1
- package/dist/component/stats.d.ts +1 -1
- package/dist/component/stats.js +1 -1
- package/dist/component/stats.js.map +1 -1
- package/dist/component/worker.d.ts +7 -2
- package/dist/component/worker.d.ts.map +1 -1
- package/dist/component/worker.js +37 -7
- package/dist/component/worker.js.map +1 -1
- package/package.json +27 -24
- package/src/client/index.ts +42 -6
- package/src/component/_generated/server.ts +0 -5
- package/src/component/complete.ts +88 -12
- package/src/component/config.ts +1 -4
- package/src/component/crons.ts +2 -2
- package/src/component/danger.ts +95 -67
- package/src/component/lib.ts +54 -4
- package/src/component/loop.ts +2 -2
- package/src/component/recovery.ts +7 -7
- package/src/component/schema.ts +10 -1
- package/src/component/stats.test.ts +1 -1
- package/src/component/stats.ts +1 -1
- package/src/component/worker.ts +46 -7
package/src/component/worker.ts
CHANGED
|
@@ -6,26 +6,40 @@
|
|
|
6
6
|
import type { FunctionHandle } from "convex/server";
|
|
7
7
|
import { v } from "convex/values";
|
|
8
8
|
import { internal } from "./_generated/api.js";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
internalAction,
|
|
11
|
+
internalMutation,
|
|
12
|
+
internalQuery,
|
|
13
|
+
} from "./_generated/server.js";
|
|
10
14
|
import { createLogger, logLevel } from "./logging.js";
|
|
11
15
|
import type { RunResult } from "./shared.js";
|
|
16
|
+
import { assert } from "convex-helpers";
|
|
12
17
|
|
|
13
18
|
export const runMutationWrapper = internalMutation({
|
|
14
19
|
args: {
|
|
15
20
|
workId: v.id("work"),
|
|
16
21
|
fnHandle: v.string(),
|
|
17
|
-
|
|
22
|
+
payloadId: v.optional(v.id("payload")),
|
|
23
|
+
fnArgs: v.optional(v.record(v.string(), v.any())),
|
|
18
24
|
fnType: v.union(v.literal("query"), v.literal("mutation")),
|
|
19
25
|
logLevel,
|
|
20
26
|
attempt: v.number(),
|
|
21
27
|
},
|
|
22
28
|
handler: async (ctx, { workId, attempt, ...args }) => {
|
|
23
29
|
const console = createLogger(args.logLevel);
|
|
24
|
-
|
|
30
|
+
|
|
31
|
+
let fnArgs = args.fnArgs;
|
|
32
|
+
if (!fnArgs) {
|
|
33
|
+
assert(args.payloadId);
|
|
34
|
+
const payload = await ctx.db.get(args.payloadId);
|
|
35
|
+
assert(payload?.args);
|
|
36
|
+
fnArgs = payload.args;
|
|
37
|
+
}
|
|
38
|
+
|
|
25
39
|
try {
|
|
26
40
|
const returnValue = await (args.fnType === "query"
|
|
27
|
-
? ctx.runQuery(fnHandle as FunctionHandle<"query">,
|
|
28
|
-
: ctx.runMutation(fnHandle as FunctionHandle<"mutation">,
|
|
41
|
+
? ctx.runQuery(args.fnHandle as FunctionHandle<"query">, fnArgs)
|
|
42
|
+
: ctx.runMutation(args.fnHandle as FunctionHandle<"mutation">, fnArgs));
|
|
29
43
|
// NOTE: we could run the `saveResult` handler here, or call `ctx.runMutation`,
|
|
30
44
|
// but we want the mutation to be a separate transaction to reduce the window for OCCs.
|
|
31
45
|
await ctx.scheduler.runAfter(0, internal.complete.complete, {
|
|
@@ -54,15 +68,26 @@ export const runActionWrapper = internalAction({
|
|
|
54
68
|
args: {
|
|
55
69
|
workId: v.id("work"),
|
|
56
70
|
fnHandle: v.string(),
|
|
57
|
-
fnArgs: v.any(),
|
|
71
|
+
fnArgs: v.optional(v.record(v.string(), v.any())),
|
|
72
|
+
payloadId: v.optional(v.id("payload")),
|
|
58
73
|
logLevel,
|
|
59
74
|
attempt: v.number(),
|
|
60
75
|
},
|
|
61
76
|
handler: async (ctx, { workId, attempt, ...args }) => {
|
|
62
77
|
const console = createLogger(args.logLevel);
|
|
78
|
+
|
|
79
|
+
// Fetch args from payload if stored separately
|
|
80
|
+
let fnArgs = args.fnArgs;
|
|
81
|
+
if (fnArgs === undefined) {
|
|
82
|
+
assert(args.payloadId);
|
|
83
|
+
fnArgs = await ctx.runQuery(internal.worker.getWorkArgs, {
|
|
84
|
+
payloadId: args.payloadId,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
63
88
|
const fnHandle = args.fnHandle as FunctionHandle<"action">;
|
|
64
89
|
try {
|
|
65
|
-
const returnValue = await ctx.runAction(fnHandle,
|
|
90
|
+
const returnValue = await ctx.runAction(fnHandle, fnArgs);
|
|
66
91
|
// NOTE: we could run `ctx.runMutation`, but we want to guarantee execution,
|
|
67
92
|
// and `ctx.scheduler.runAfter` won't OCC.
|
|
68
93
|
const runResult: RunResult = { kind: "success", returnValue };
|
|
@@ -80,5 +105,19 @@ export const runActionWrapper = internalAction({
|
|
|
80
105
|
},
|
|
81
106
|
});
|
|
82
107
|
|
|
108
|
+
// Helper mutation for actions to fetch work args
|
|
109
|
+
export const getWorkArgs = internalQuery({
|
|
110
|
+
args: {
|
|
111
|
+
payloadId: v.id("payload"),
|
|
112
|
+
},
|
|
113
|
+
returns: v.record(v.string(), v.any()),
|
|
114
|
+
handler: async (ctx, args) => {
|
|
115
|
+
const payload = await ctx.db.get("payload", args.payloadId);
|
|
116
|
+
assert(payload);
|
|
117
|
+
assert(payload.args);
|
|
118
|
+
return payload.args;
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
|
|
83
122
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
84
123
|
const console = "THIS IS A REMINDER TO USE createLogger";
|