@convex-dev/workpool 0.2.0 → 0.2.2
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/README.md +86 -3
- package/dist/commonjs/client/index.d.ts +32 -6
- package/dist/commonjs/client/index.d.ts.map +1 -1
- package/dist/commonjs/client/index.js +28 -2
- package/dist/commonjs/client/index.js.map +1 -1
- package/dist/commonjs/component/complete.d.ts.map +1 -1
- package/dist/commonjs/component/complete.js +9 -7
- package/dist/commonjs/component/complete.js.map +1 -1
- package/dist/commonjs/component/kick.d.ts +3 -2
- package/dist/commonjs/component/kick.d.ts.map +1 -1
- package/dist/commonjs/component/kick.js +12 -9
- package/dist/commonjs/component/kick.js.map +1 -1
- package/dist/commonjs/component/lib.d.ts +3 -3
- package/dist/commonjs/component/lib.d.ts.map +1 -1
- package/dist/commonjs/component/lib.js +25 -19
- package/dist/commonjs/component/lib.js.map +1 -1
- package/dist/commonjs/component/logging.d.ts +3 -2
- package/dist/commonjs/component/logging.d.ts.map +1 -1
- package/dist/commonjs/component/logging.js +34 -15
- package/dist/commonjs/component/logging.js.map +1 -1
- package/dist/commonjs/component/loop.js +10 -10
- package/dist/commonjs/component/loop.js.map +1 -1
- package/dist/commonjs/component/recovery.d.ts +29 -0
- package/dist/commonjs/component/recovery.d.ts.map +1 -1
- package/dist/commonjs/component/recovery.js +69 -66
- package/dist/commonjs/component/recovery.js.map +1 -1
- package/dist/commonjs/component/schema.d.ts +11 -11
- package/dist/commonjs/component/shared.d.ts +4 -4
- package/dist/commonjs/component/shared.d.ts.map +1 -1
- package/dist/commonjs/component/shared.js +2 -2
- package/dist/commonjs/component/shared.js.map +1 -1
- package/dist/commonjs/component/stats.d.ts +20 -21
- package/dist/commonjs/component/stats.d.ts.map +1 -1
- package/dist/commonjs/component/stats.js +86 -38
- package/dist/commonjs/component/stats.js.map +1 -1
- package/dist/commonjs/component/worker.d.ts +2 -2
- package/dist/esm/client/index.d.ts +32 -6
- package/dist/esm/client/index.d.ts.map +1 -1
- package/dist/esm/client/index.js +28 -2
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/component/complete.d.ts.map +1 -1
- package/dist/esm/component/complete.js +9 -7
- package/dist/esm/component/complete.js.map +1 -1
- package/dist/esm/component/kick.d.ts +3 -2
- package/dist/esm/component/kick.d.ts.map +1 -1
- package/dist/esm/component/kick.js +12 -9
- package/dist/esm/component/kick.js.map +1 -1
- package/dist/esm/component/lib.d.ts +3 -3
- package/dist/esm/component/lib.d.ts.map +1 -1
- package/dist/esm/component/lib.js +25 -19
- package/dist/esm/component/lib.js.map +1 -1
- package/dist/esm/component/logging.d.ts +3 -2
- package/dist/esm/component/logging.d.ts.map +1 -1
- package/dist/esm/component/logging.js +34 -15
- package/dist/esm/component/logging.js.map +1 -1
- package/dist/esm/component/loop.js +10 -10
- package/dist/esm/component/loop.js.map +1 -1
- package/dist/esm/component/recovery.d.ts +29 -0
- package/dist/esm/component/recovery.d.ts.map +1 -1
- package/dist/esm/component/recovery.js +69 -66
- package/dist/esm/component/recovery.js.map +1 -1
- package/dist/esm/component/schema.d.ts +11 -11
- package/dist/esm/component/shared.d.ts +4 -4
- package/dist/esm/component/shared.d.ts.map +1 -1
- package/dist/esm/component/shared.js +2 -2
- package/dist/esm/component/shared.js.map +1 -1
- package/dist/esm/component/stats.d.ts +20 -21
- package/dist/esm/component/stats.d.ts.map +1 -1
- package/dist/esm/component/stats.js +86 -38
- package/dist/esm/component/stats.js.map +1 -1
- package/dist/esm/component/worker.d.ts +2 -2
- package/package.json +6 -7
- package/src/client/index.ts +66 -36
- package/src/component/_generated/api.d.ts +6 -6
- package/src/component/complete.ts +18 -7
- package/src/component/kick.test.ts +17 -7
- package/src/component/kick.ts +14 -11
- package/src/component/lib.ts +33 -26
- package/src/component/logging.test.ts +16 -0
- package/src/component/logging.ts +45 -23
- package/src/component/loop.test.ts +12 -12
- package/src/component/loop.ts +11 -11
- package/src/component/recovery.test.ts +6 -11
- package/src/component/recovery.ts +77 -69
- package/src/component/shared.ts +2 -2
- package/src/component/stats.test.ts +345 -0
- package/src/component/stats.ts +111 -41
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recovery.js","sourceRoot":"","sources":["../../../src/component/recovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,CAAC,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"recovery.js","sourceRoot":"","sources":["../../../src/component/recovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,CAAC,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAe,MAAM,wBAAwB,CAAC;AACvE,OAAO,EAAgB,eAAe,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5B,IAAI,EAAE,CAAC,CAAC,KAAK,CACX,CAAC,CAAC,MAAM,CAAC;QACP,WAAW,EAAE,CAAC,CAAC,EAAE,CAAC,sBAAsB,CAAC;QACzC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC;QACpB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;QACnB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;KACpB,CAAC,CACH;CACF,CAAC,CAAC;AAEH;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,gBAAgB,CAAC;IACtC,IAAI,EAAE,YAAY;IAClB,OAAO,EAAE,eAAe;CACzB,CAAC,CAAC;AAEH,4BAA4B;AAC5B,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,GAAgB,EAChB,EAAE,IAAI,EAA8B;IAEpC,MAAM,OAAO,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,CAAC;IACvD,MAAM,OAAO,GAA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AAC,GAAG,QAAQ,oCAAoC,CAAC,CAAC;YAC9D,UAAU,CAAC,IAAI,CAAC;gBACd,MAAM,EAAE,GAAG,CAAC,MAAM;gBAClB,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,yBAAyB,EAAE;gBAC/D,OAAO,EAAE,GAAG,CAAC,OAAO;aACrB,CAAC,CAAC;YACH,SAAS;SACV;QACD,qEAAqE;QACrE,iDAAiD;QACjD,QAAQ,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE;YAC5B,KAAK,QAAQ,CAAC,CAAC;gBACb,OAAO,CAAC,KAAK,CAAC,GAAG,QAAQ,kCAAkC,CAAC,CAAC;gBAC7D,UAAU,CAAC,IAAI,CAAC;oBACd,MAAM,EAAE,GAAG,CAAC,MAAM;oBAClB,SAAS,EAAE,SAAS,CAAC,KAAK;oBAC1B,OAAO,EAAE,GAAG,CAAC,OAAO;iBACrB,CAAC,CAAC;gBACH,MAAM;aACP;YACD,KAAK,UAAU,CAAC,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,GAAG,QAAQ,wCAAwC,CAAC,CAAC;gBACnE,UAAU,CAAC,IAAI,CAAC;oBACd,MAAM,EAAE,GAAG,CAAC,MAAM;oBAClB,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,wBAAwB,EAAE;oBAC9D,OAAO,EAAE,GAAG,CAAC,OAAO;iBACrB,CAAC,CAAC;gBACH,MAAM;aACP;SACF;KACF;IACD,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE;QACzB,MAAM,eAAe,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;KAClD;AACH,CAAC"}
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
declare const _default: import("convex/server").SchemaDefinition<{
|
|
2
2
|
globals: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
3
3
|
maxParallelism: number;
|
|
4
|
-
logLevel: "DEBUG" | "INFO" | "WARN" | "ERROR";
|
|
4
|
+
logLevel: "DEBUG" | "INFO" | "REPORT" | "WARN" | "ERROR";
|
|
5
5
|
}, {
|
|
6
6
|
maxParallelism: import("convex/values").VFloat64<number, "required">;
|
|
7
|
-
logLevel: import("convex/values").VUnion<"DEBUG" | "INFO" | "WARN" | "ERROR", [import("convex/values").VLiteral<"DEBUG", "required">, import("convex/values").VLiteral<"INFO", "required">, import("convex/values").VLiteral<"WARN", "required">, import("convex/values").VLiteral<"ERROR", "required">], "required", never>;
|
|
7
|
+
logLevel: import("convex/values").VUnion<"DEBUG" | "INFO" | "REPORT" | "WARN" | "ERROR", [import("convex/values").VLiteral<"DEBUG", "required">, import("convex/values").VLiteral<"INFO", "required">, import("convex/values").VLiteral<"REPORT", "required">, import("convex/values").VLiteral<"WARN", "required">, import("convex/values").VLiteral<"ERROR", "required">], "required", never>;
|
|
8
8
|
}, "required", "maxParallelism" | "logLevel">, {}, {}, {}>;
|
|
9
9
|
internalState: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
10
|
+
report: {
|
|
11
|
+
failed: number;
|
|
12
|
+
canceled: number;
|
|
13
|
+
completed: number;
|
|
14
|
+
succeeded: number;
|
|
15
|
+
retries: number;
|
|
16
|
+
lastReportTs: number;
|
|
17
|
+
};
|
|
10
18
|
running: {
|
|
11
19
|
workId: import("convex/values").GenericId<"work">;
|
|
12
20
|
scheduledId: import("convex/values").GenericId<"_scheduled_functions">;
|
|
@@ -19,14 +27,6 @@ declare const _default: import("convex/server").SchemaDefinition<{
|
|
|
19
27
|
completion: bigint;
|
|
20
28
|
cancelation: bigint;
|
|
21
29
|
};
|
|
22
|
-
report: {
|
|
23
|
-
failed: number;
|
|
24
|
-
canceled: number;
|
|
25
|
-
completed: number;
|
|
26
|
-
succeeded: number;
|
|
27
|
-
retries: number;
|
|
28
|
-
lastReportTs: number;
|
|
29
|
-
};
|
|
30
30
|
}, {
|
|
31
31
|
generation: import("convex/values").VInt64<bigint, "required">;
|
|
32
32
|
segmentCursors: import("convex/values").VObject<{
|
|
@@ -67,7 +67,7 @@ declare const _default: import("convex/server").SchemaDefinition<{
|
|
|
67
67
|
scheduledId: import("convex/values").VId<import("convex/values").GenericId<"_scheduled_functions">, "required">;
|
|
68
68
|
started: import("convex/values").VFloat64<number, "required">;
|
|
69
69
|
}, "required", "workId" | "scheduledId" | "started">, "required">;
|
|
70
|
-
}, "required", "running" | "lastRecovery" | "generation" | "segmentCursors" | "report
|
|
70
|
+
}, "required", "report" | "running" | "lastRecovery" | "generation" | "segmentCursors" | "report.failed" | "report.canceled" | "report.completed" | "report.succeeded" | "report.retries" | "report.lastReportTs" | "segmentCursors.incoming" | "segmentCursors.completion" | "segmentCursors.cancelation">, {}, {}, {}>;
|
|
71
71
|
runStatus: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
72
72
|
state: {
|
|
73
73
|
kind: "running";
|
|
@@ -7,15 +7,15 @@ export declare const HOUR: number;
|
|
|
7
7
|
export declare const DAY: number;
|
|
8
8
|
export declare const YEAR: number;
|
|
9
9
|
export declare function toSegment(ms: number): bigint;
|
|
10
|
-
export declare function
|
|
11
|
-
export declare function
|
|
10
|
+
export declare function getCurrentSegment(): bigint;
|
|
11
|
+
export declare function getNextSegment(): bigint;
|
|
12
12
|
export declare function fromSegment(segment: bigint): number;
|
|
13
13
|
export declare const config: import("convex/values").VObject<{
|
|
14
14
|
maxParallelism: number;
|
|
15
|
-
logLevel: "DEBUG" | "INFO" | "WARN" | "ERROR";
|
|
15
|
+
logLevel: "DEBUG" | "INFO" | "REPORT" | "WARN" | "ERROR";
|
|
16
16
|
}, {
|
|
17
17
|
maxParallelism: import("convex/values").VFloat64<number, "required">;
|
|
18
|
-
logLevel: import("convex/values").VUnion<"DEBUG" | "INFO" | "WARN" | "ERROR", [import("convex/values").VLiteral<"DEBUG", "required">, import("convex/values").VLiteral<"INFO", "required">, import("convex/values").VLiteral<"WARN", "required">, import("convex/values").VLiteral<"ERROR", "required">], "required", never>;
|
|
18
|
+
logLevel: import("convex/values").VUnion<"DEBUG" | "INFO" | "REPORT" | "WARN" | "ERROR", [import("convex/values").VLiteral<"DEBUG", "required">, import("convex/values").VLiteral<"INFO", "required">, import("convex/values").VLiteral<"REPORT", "required">, import("convex/values").VLiteral<"WARN", "required">, import("convex/values").VLiteral<"ERROR", "required">], "required", never>;
|
|
19
19
|
}, "required", "maxParallelism" | "logLevel">;
|
|
20
20
|
export type Config = Infer<typeof config>;
|
|
21
21
|
export declare const retryBehavior: import("convex/values").VObject<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/component/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAGtC,OAAO,EAAE,MAAM,EAAY,MAAM,cAAc,CAAC;AAEhD,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAE1C,eAAO,MAAM,MAAM,OAAO,CAAC;AAC3B,eAAO,MAAM,MAAM,QAAc,CAAC;AAClC,eAAO,MAAM,IAAI,QAAc,CAAC;AAChC,eAAO,MAAM,GAAG,QAAY,CAAC;AAC7B,eAAO,MAAM,IAAI,QAAY,CAAC;AAE9B,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED,wBAAgB,
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/component/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAGtC,OAAO,EAAE,MAAM,EAAY,MAAM,cAAc,CAAC;AAEhD,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAE1C,eAAO,MAAM,MAAM,OAAO,CAAC;AAC3B,eAAO,MAAM,MAAM,QAAc,CAAC;AAClC,eAAO,MAAM,IAAI,QAAc,CAAC;AAChC,eAAO,MAAM,GAAG,QAAY,CAAC;AAC7B,eAAO,MAAM,IAAI,Q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SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAEnD;AAED;;GAEG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAEnD"}
|
|
@@ -10,10 +10,10 @@ export const YEAR = 365 * DAY;
|
|
|
10
10
|
export function toSegment(ms) {
|
|
11
11
|
return BigInt(Math.floor(ms / SEGMENT_MS));
|
|
12
12
|
}
|
|
13
|
-
export function
|
|
13
|
+
export function getCurrentSegment() {
|
|
14
14
|
return toSegment(Date.now());
|
|
15
15
|
}
|
|
16
|
-
export function
|
|
16
|
+
export function getNextSegment() {
|
|
17
17
|
return toSegment(Date.now()) + 1n;
|
|
18
18
|
}
|
|
19
19
|
export function fromSegment(segment) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/component/shared.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAU,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAC1C,MAAM,UAAU,GAAG,GAAG,CAAC;AACvB,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,CAAC;AAC3B,MAAM,CAAC,MAAM,MAAM,GAAG,EAAE,GAAG,MAAM,CAAC;AAClC,MAAM,CAAC,MAAM,IAAI,GAAG,EAAE,GAAG,MAAM,CAAC;AAChC,MAAM,CAAC,MAAM,GAAG,GAAG,EAAE,GAAG,IAAI,CAAC;AAC7B,MAAM,CAAC,MAAM,IAAI,GAAG,GAAG,GAAG,GAAG,CAAC;AAE9B,MAAM,UAAU,SAAS,CAAC,EAAU;IAClC,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC;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,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC;CAC7B,CAAC,CACH,CACF,CAAC;AAGF,MAAM,UAAU,kBAAkB,CAAC,EAAU,EAAE,OAAe;IAC5D,IAAI,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE;QAC1B,OAAO,CAAC,KAAK,CAAC,8CAA8C,EAAE,EAAE,CAAC,CAAC;QAClE,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC;KACnB;IACD,IAAI,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,EAAE;QAC9B,OAAO,CAAC,KAAK,CACX,wEAAwE,EACxE,EAAE,CACH,CAAC;QACF,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;KAC1B;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,GAAG,CAAmB,CAAI,EAAE,CAAI;IAC9C,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACvB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,GAAG,CAAmB,CAAI,EAAE,CAAI;IAC9C,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACvB,CAAC"}
|
|
@@ -1,21 +1,10 @@
|
|
|
1
1
|
import { Doc, Id } from "./_generated/dataModel.js";
|
|
2
|
+
import { MutationCtx } from "./_generated/server.js";
|
|
3
|
+
import { Config } from "./shared.js";
|
|
2
4
|
import { Logger } from "./logging.js";
|
|
3
5
|
/**
|
|
4
6
|
* Record stats about work execution. Intended to be queried by Axiom or Datadog.
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Sample axiom dashboard query:
|
|
8
|
-
|
|
9
|
-
workpool
|
|
10
|
-
| extend parsed_message = iff(
|
|
11
|
-
isnotnull(parse_json(trim("'", tostring(["data.message"])))),
|
|
12
|
-
parse_json(trim("'", tostring(["data.message"]))),
|
|
13
|
-
parse_json('{}')
|
|
14
|
-
)
|
|
15
|
-
| extend startLag = parsed_message["startLag"]
|
|
16
|
-
| extend fnName = parsed_message["fnName"]
|
|
17
|
-
| summarize avg(todouble(startLag)) by bin_auto(_time), tostring(fnName)
|
|
18
|
-
|
|
7
|
+
* See the [README](https://github.com/get-convex/workpool) for example queries.
|
|
19
8
|
*/
|
|
20
9
|
export declare function recordEnqueued(console: Logger, data: {
|
|
21
10
|
workId: Id<"work">;
|
|
@@ -24,17 +13,27 @@ export declare function recordEnqueued(console: Logger, data: {
|
|
|
24
13
|
}): void;
|
|
25
14
|
export declare function recordStarted(console: Logger, work: Doc<"work">, lagMs: number): void;
|
|
26
15
|
export declare function recordCompleted(console: Logger, work: Doc<"work">, status: "success" | "failed" | "canceled" | "retrying"): void;
|
|
27
|
-
export declare function
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
16
|
+
export declare function generateReport(ctx: MutationCtx, console: Logger, state: Doc<"internalState">, { maxParallelism, logLevel }: Config): Promise<void>;
|
|
17
|
+
export declare const calculateBacklogAndReport: import("convex/server").RegisteredMutation<"internal", {
|
|
18
|
+
report: {
|
|
19
|
+
failed: number;
|
|
20
|
+
canceled: number;
|
|
21
|
+
completed: number;
|
|
22
|
+
succeeded: number;
|
|
23
|
+
retries: number;
|
|
24
|
+
lastReportTs: number;
|
|
25
|
+
};
|
|
26
|
+
logLevel: "DEBUG" | "INFO" | "REPORT" | "WARN" | "ERROR";
|
|
27
|
+
running: number;
|
|
28
|
+
startSegment: bigint;
|
|
29
|
+
endSegment: bigint;
|
|
30
|
+
cursor: string;
|
|
31
|
+
}, Promise<void>>;
|
|
33
32
|
/**
|
|
34
33
|
* Warning: this should not be used from a mutation, as it will cause conflicts.
|
|
35
34
|
* Use this while developing to see the state of the queue.
|
|
36
35
|
*/
|
|
37
|
-
export declare const
|
|
36
|
+
export declare const diagnostics: import("convex/server").RegisteredQuery<"internal", {}, Promise<{
|
|
38
37
|
canceling: any;
|
|
39
38
|
waiting: any;
|
|
40
39
|
running: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../../../src/component/stats.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../../../src/component/stats.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,2BAA2B,CAAC;AACpD,OAAO,EAGL,WAAW,EACZ,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,MAAM,EAGP,MAAM,aAAa,CAAC;AACrB,OAAO,EAAgB,MAAM,EAAuB,MAAM,cAAc,CAAC;AAOzE;;;GAGG;AAEH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE;IACJ,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf,QAMF;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,EACjB,KAAK,EAAE,MAAM,QASd;AAED,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,EACjB,MAAM,EAAE,SAAS,GAAG,QAAQ,GAAG,UAAU,GAAG,UAAU,QASvD;AAED,wBAAsB,cAAc,CAClC,GAAG,EAAE,WAAW,EAChB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,GAAG,CAAC,eAAe,CAAC,EAC3B,EAAE,cAAc,EAAE,QAAQ,EAAE,EAAE,MAAM,iBAkCrC;AAED,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;iBAyCpC,CAAC;AAiBH;;;GAGG;AACH,eAAO,MAAM,WAAW;;;;;;;;GA4BtB,CAAC"}
|
|
@@ -1,22 +1,14 @@
|
|
|
1
1
|
import { v } from "convex/values";
|
|
2
|
-
import { internalQuery,
|
|
3
|
-
import { DEFAULT_MAX_PARALLELISM } from "./shared.js";
|
|
2
|
+
import { internalMutation, internalQuery, } from "./_generated/server.js";
|
|
3
|
+
import { DEFAULT_MAX_PARALLELISM, getCurrentSegment, } from "./shared.js";
|
|
4
|
+
import { createLogger, logLevel, shouldLog } from "./logging.js";
|
|
5
|
+
import { internal } from "./_generated/api.js";
|
|
6
|
+
import schema from "./schema.js";
|
|
7
|
+
import { paginator } from "convex-helpers/server/pagination";
|
|
8
|
+
const BACKLOG_BATCH_SIZE = 100;
|
|
4
9
|
/**
|
|
5
10
|
* Record stats about work execution. Intended to be queried by Axiom or Datadog.
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Sample axiom dashboard query:
|
|
9
|
-
|
|
10
|
-
workpool
|
|
11
|
-
| extend parsed_message = iff(
|
|
12
|
-
isnotnull(parse_json(trim("'", tostring(["data.message"])))),
|
|
13
|
-
parse_json(trim("'", tostring(["data.message"]))),
|
|
14
|
-
parse_json('{}')
|
|
15
|
-
)
|
|
16
|
-
| extend startLag = parsed_message["startLag"]
|
|
17
|
-
| extend fnName = parsed_message["fnName"]
|
|
18
|
-
| summarize avg(todouble(startLag)) by bin_auto(_time), tostring(fnName)
|
|
19
|
-
|
|
11
|
+
* See the [README](https://github.com/get-convex/workpool) for example queries.
|
|
20
12
|
*/
|
|
21
13
|
export function recordEnqueued(console, data) {
|
|
22
14
|
console.event("enqueued", {
|
|
@@ -42,36 +34,92 @@ export function recordCompleted(console, work, status) {
|
|
|
42
34
|
status,
|
|
43
35
|
});
|
|
44
36
|
}
|
|
45
|
-
export function
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
37
|
+
export async function generateReport(ctx, console, state, { maxParallelism, logLevel }) {
|
|
38
|
+
if (!shouldLog(logLevel, "REPORT")) {
|
|
39
|
+
// Don't waste time if we're not going to log.
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const currentSegment = getCurrentSegment();
|
|
43
|
+
const pendingStart = await paginator(ctx.db, schema)
|
|
44
|
+
.query("pendingStart")
|
|
45
|
+
.withIndex("segment", (q) => q
|
|
46
|
+
.gte("segment", state.segmentCursors.incoming)
|
|
47
|
+
.lt("segment", currentSegment))
|
|
48
|
+
.paginate({
|
|
49
|
+
numItems: maxParallelism,
|
|
50
|
+
cursor: null,
|
|
56
51
|
});
|
|
52
|
+
if (pendingStart.isDone) {
|
|
53
|
+
recordReport(console, {
|
|
54
|
+
...state.report,
|
|
55
|
+
running: state.running.length,
|
|
56
|
+
backlog: pendingStart.page.length,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
await ctx.scheduler.runAfter(0, internal.stats.calculateBacklogAndReport, {
|
|
61
|
+
startSegment: state.segmentCursors.incoming,
|
|
62
|
+
endSegment: currentSegment,
|
|
63
|
+
cursor: pendingStart.continueCursor,
|
|
64
|
+
report: state.report,
|
|
65
|
+
running: state.running.length,
|
|
66
|
+
logLevel,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
57
69
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
70
|
+
export const calculateBacklogAndReport = internalMutation({
|
|
71
|
+
args: {
|
|
72
|
+
startSegment: v.int64(),
|
|
73
|
+
endSegment: v.int64(),
|
|
74
|
+
cursor: v.string(),
|
|
75
|
+
report: schema.tables.internalState.validator.fields.report,
|
|
76
|
+
running: v.number(),
|
|
77
|
+
logLevel,
|
|
78
|
+
},
|
|
79
|
+
handler: async (ctx, args) => {
|
|
80
|
+
const pendingStart = await paginator(ctx.db, schema)
|
|
81
|
+
.query("pendingStart")
|
|
82
|
+
.withIndex("segment", (q) => q.gte("segment", args.startSegment).lt("segment", args.endSegment))
|
|
83
|
+
.paginate({
|
|
84
|
+
numItems: BACKLOG_BATCH_SIZE,
|
|
85
|
+
cursor: args.cursor,
|
|
86
|
+
});
|
|
87
|
+
const console = createLogger(args.logLevel);
|
|
88
|
+
if (pendingStart.isDone) {
|
|
89
|
+
recordReport(console, {
|
|
90
|
+
...args.report,
|
|
91
|
+
running: args.running,
|
|
92
|
+
backlog: pendingStart.page.length,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
await ctx.scheduler.runAfter(0, internal.stats.calculateBacklogAndReport, {
|
|
97
|
+
startSegment: args.startSegment,
|
|
98
|
+
endSegment: args.endSegment,
|
|
99
|
+
cursor: pendingStart.continueCursor,
|
|
100
|
+
report: args.report,
|
|
101
|
+
running: args.running,
|
|
102
|
+
logLevel: args.logLevel,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
68
105
|
},
|
|
69
106
|
});
|
|
107
|
+
function recordReport(console, report) {
|
|
108
|
+
const { completed, failed, retries } = report;
|
|
109
|
+
const withoutRetries = completed - retries;
|
|
110
|
+
const failureRate = completed ? (failed + retries) / completed : 0;
|
|
111
|
+
const permanentFailureRate = withoutRetries ? failed / withoutRetries : 0;
|
|
112
|
+
console.event("report", {
|
|
113
|
+
...report,
|
|
114
|
+
failureRate: Number(failureRate.toFixed(4)),
|
|
115
|
+
permanentFailureRate: Number(permanentFailureRate.toFixed(4)),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
70
118
|
/**
|
|
71
119
|
* Warning: this should not be used from a mutation, as it will cause conflicts.
|
|
72
120
|
* Use this while developing to see the state of the queue.
|
|
73
121
|
*/
|
|
74
|
-
export const
|
|
122
|
+
export const diagnostics = internalQuery({
|
|
75
123
|
args: {},
|
|
76
124
|
returns: v.any(),
|
|
77
125
|
handler: async (ctx) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stats.js","sourceRoot":"","sources":["../../../src/component/stats.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAElC,OAAO,
|
|
1
|
+
{"version":3,"file":"stats.js","sourceRoot":"","sources":["../../../src/component/stats.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAElC,OAAO,EACL,gBAAgB,EAChB,aAAa,GAEd,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAEL,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,YAAY,EAAU,QAAQ,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAE7D,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAE/B;;;GAGG;AAEH,MAAM,UAAU,cAAc,CAC5B,OAAe,EACf,IAIC;IAED,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE;QACxB,GAAG,IAAI;QACP,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE;KACvB,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,aAAa,CAC3B,OAAe,EACf,IAAiB,EACjB,KAAa;IAEb,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE;QACvB,MAAM,EAAE,IAAI,CAAC,GAAG;QAChB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,UAAU,EAAE,IAAI,CAAC,aAAa;QAC9B,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;QACrB,QAAQ,EAAE,KAAK;KAChB,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,OAA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logLevel: "DEBUG" | "INFO" | "REPORT" | "WARN" | "ERROR";
|
|
3
3
|
fnHandle: string;
|
|
4
4
|
workId: import("convex/values").GenericId<"work">;
|
|
5
5
|
fnArgs: any;
|
|
6
6
|
attempt: number;
|
|
7
7
|
}, Promise<void>>;
|
|
8
8
|
export declare const runActionWrapper: import("convex/server").RegisteredAction<"internal", {
|
|
9
|
-
logLevel: "DEBUG" | "INFO" | "WARN" | "ERROR";
|
|
9
|
+
logLevel: "DEBUG" | "INFO" | "REPORT" | "WARN" | "ERROR";
|
|
10
10
|
fnHandle: string;
|
|
11
11
|
workId: import("convex/values").GenericId<"work">;
|
|
12
12
|
fnArgs: any;
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"email": "support@convex.dev",
|
|
8
8
|
"url": "https://github.com/get-convex/workpool/issues"
|
|
9
9
|
},
|
|
10
|
-
"version": "0.2.
|
|
10
|
+
"version": "0.2.2",
|
|
11
11
|
"license": "Apache-2.0",
|
|
12
12
|
"keywords": [
|
|
13
13
|
"convex",
|
|
@@ -62,11 +62,14 @@
|
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
|
-
"convex": ">=1.17.0 <1.25.0"
|
|
65
|
+
"convex": ">=1.17.0 <1.25.0",
|
|
66
|
+
"convex-helpers": "^0.1.71"
|
|
66
67
|
},
|
|
67
68
|
"devDependencies": {
|
|
69
|
+
"@edge-runtime/vm": "^4.0.4",
|
|
68
70
|
"@eslint/js": "^9.9.1",
|
|
69
71
|
"@types/node": "^18.17.0",
|
|
72
|
+
"@vitest/coverage-v8": "^2.1.9",
|
|
70
73
|
"convex-test": "^0.0.36-alpha.0",
|
|
71
74
|
"eslint": "^9.9.1",
|
|
72
75
|
"globals": "^15.9.0",
|
|
@@ -77,9 +80,5 @@
|
|
|
77
80
|
},
|
|
78
81
|
"main": "./dist/commonjs/client/index.js",
|
|
79
82
|
"types": "./dist/commonjs/client/index.d.ts",
|
|
80
|
-
"module": "./dist/esm/client/index.js"
|
|
81
|
-
"dependencies": {
|
|
82
|
-
"@edge-runtime/vm": "^4.0.4",
|
|
83
|
-
"@vitest/coverage-v8": "^2.1.9"
|
|
84
|
-
}
|
|
83
|
+
"module": "./dist/esm/client/index.js"
|
|
85
84
|
}
|
package/src/client/index.ts
CHANGED
|
@@ -23,7 +23,8 @@ import {
|
|
|
23
23
|
Status,
|
|
24
24
|
} from "../component/shared.js";
|
|
25
25
|
import { RunMutationCtx, RunQueryCtx, UseApi } from "./utils.js";
|
|
26
|
-
export { resultValidator, type RunResult };
|
|
26
|
+
export { resultValidator, type RunResult, type RetryBehavior };
|
|
27
|
+
export { retryBehavior as vRetryBehavior } from "../component/shared.js";
|
|
27
28
|
|
|
28
29
|
// Attempts will run with delay [0, 250, 500, 1000, 2000] (ms)
|
|
29
30
|
export const DEFAULT_RETRY_BEHAVIOR: RetryBehavior = {
|
|
@@ -55,17 +56,20 @@ export class Workpool {
|
|
|
55
56
|
maxParallelism?: number;
|
|
56
57
|
/** How much to log. This is updated on each call to `enqueue*`,
|
|
57
58
|
* `status`, or `cancel*`.
|
|
58
|
-
* Default is
|
|
59
|
-
* With INFO, you can see events for started and completed work
|
|
60
|
-
* be parsed by tools like
|
|
59
|
+
* Default is REPORT, which logs warnings, errors, and a periodic report.
|
|
60
|
+
* With INFO, you can also see events for started and completed work.
|
|
61
|
+
* Stats generated can be parsed by tools like
|
|
62
|
+
* [Axiom](https://axiom.co) for monitoring.
|
|
61
63
|
* With DEBUG, you can see timers and internal events for work being
|
|
62
64
|
* scheduled.
|
|
63
65
|
*/
|
|
64
66
|
logLevel?: LogLevel;
|
|
65
|
-
/** Default retry behavior for enqueued actions.
|
|
67
|
+
/** Default retry behavior for enqueued actions.
|
|
68
|
+
* See {@link RetryBehavior}.
|
|
69
|
+
*/
|
|
66
70
|
defaultRetryBehavior?: RetryBehavior;
|
|
67
71
|
/** Whether to retry actions that fail by default. Default: false.
|
|
68
|
-
* NOTE: Only
|
|
72
|
+
* NOTE: Only enable this if your actions are idempotent.
|
|
69
73
|
* See the docs (README.md) for more details.
|
|
70
74
|
*/
|
|
71
75
|
retryActionsByDefault?: boolean;
|
|
@@ -151,52 +155,44 @@ export class Workpool {
|
|
|
151
155
|
});
|
|
152
156
|
return id as WorkId;
|
|
153
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Cancels a work item. If it's already started, it will be allowed to finish
|
|
160
|
+
* but will not be retried.
|
|
161
|
+
*
|
|
162
|
+
* @param ctx - The mutation or action context that can call ctx.runMutation.
|
|
163
|
+
* @param id - The ID of the work to cancel.
|
|
164
|
+
*/
|
|
154
165
|
async cancel(ctx: RunMutationCtx, id: WorkId): Promise<void> {
|
|
155
166
|
await ctx.runMutation(this.component.lib.cancel, {
|
|
156
167
|
id,
|
|
157
168
|
logLevel: this.options.logLevel ?? getDefaultLogLevel(),
|
|
158
169
|
});
|
|
159
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Cancels all pending work items. See {@link cancel}.
|
|
173
|
+
*
|
|
174
|
+
* @param ctx - The mutation or action context that can call ctx.runMutation.
|
|
175
|
+
*/
|
|
160
176
|
async cancelAll(ctx: RunMutationCtx): Promise<void> {
|
|
161
177
|
await ctx.runMutation(this.component.lib.cancelAll, {
|
|
162
178
|
logLevel: this.options.logLevel ?? getDefaultLogLevel(),
|
|
163
179
|
});
|
|
164
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Gets the status of a work item.
|
|
183
|
+
*
|
|
184
|
+
* @param ctx - The query context that can call ctx.runQuery.
|
|
185
|
+
* @param id - The ID of the work to get the status of.
|
|
186
|
+
* @returns The status of the work item. One of:
|
|
187
|
+
* - `{ state: "pending", previousAttempts: number }`
|
|
188
|
+
* - `{ state: "running", previousAttempts: number }`
|
|
189
|
+
* - `{ state: "finished" }`
|
|
190
|
+
*/
|
|
165
191
|
async status(ctx: RunQueryCtx, id: WorkId): Promise<Status> {
|
|
166
192
|
return ctx.runQuery(this.component.lib.status, { id });
|
|
167
193
|
}
|
|
168
194
|
}
|
|
169
195
|
|
|
170
|
-
function getRetryBehavior(
|
|
171
|
-
defaultRetryBehavior: RetryBehavior | undefined,
|
|
172
|
-
retryActionsByDefault: boolean | undefined,
|
|
173
|
-
retryOverride: boolean | RetryBehavior | undefined
|
|
174
|
-
): RetryBehavior | undefined {
|
|
175
|
-
const defaultRetry = defaultRetryBehavior ?? DEFAULT_RETRY_BEHAVIOR;
|
|
176
|
-
const retryByDefault = retryActionsByDefault ?? false;
|
|
177
|
-
if (retryOverride === true) {
|
|
178
|
-
return defaultRetry;
|
|
179
|
-
}
|
|
180
|
-
if (retryOverride === false) {
|
|
181
|
-
return undefined;
|
|
182
|
-
}
|
|
183
|
-
return retryOverride ?? (retryByDefault ? defaultRetry : undefined);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
async function defaultEnqueueArgs(
|
|
187
|
-
fn: FunctionReference<"action" | "mutation", FunctionVisibility>,
|
|
188
|
-
{ logLevel, maxParallelism }: Partial<Config>
|
|
189
|
-
) {
|
|
190
|
-
return {
|
|
191
|
-
fnHandle: await createFunctionHandle(fn),
|
|
192
|
-
fnName: getFunctionName(fn),
|
|
193
|
-
config: {
|
|
194
|
-
logLevel: logLevel ?? getDefaultLogLevel(),
|
|
195
|
-
maxParallelism: maxParallelism ?? DEFAULT_MAX_PARALLELISM,
|
|
196
|
-
},
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
|
|
200
196
|
export type SchedulerOptions =
|
|
201
197
|
| {
|
|
202
198
|
/**
|
|
@@ -264,6 +260,40 @@ export type OnCompleteArgs = {
|
|
|
264
260
|
// ensure OnCompleteArgs satisfies SharedOnCompleteArgs
|
|
265
261
|
const _ = {} as OnCompleteArgs satisfies SharedOnCompleteArgs;
|
|
266
262
|
|
|
263
|
+
//
|
|
264
|
+
// Helper functions
|
|
265
|
+
//
|
|
266
|
+
|
|
267
|
+
function getRetryBehavior(
|
|
268
|
+
defaultRetryBehavior: RetryBehavior | undefined,
|
|
269
|
+
retryActionsByDefault: boolean | undefined,
|
|
270
|
+
retryOverride: boolean | RetryBehavior | undefined
|
|
271
|
+
): RetryBehavior | undefined {
|
|
272
|
+
const defaultRetry = defaultRetryBehavior ?? DEFAULT_RETRY_BEHAVIOR;
|
|
273
|
+
const retryByDefault = retryActionsByDefault ?? false;
|
|
274
|
+
if (retryOverride === true) {
|
|
275
|
+
return defaultRetry;
|
|
276
|
+
}
|
|
277
|
+
if (retryOverride === false) {
|
|
278
|
+
return undefined;
|
|
279
|
+
}
|
|
280
|
+
return retryOverride ?? (retryByDefault ? defaultRetry : undefined);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
async function defaultEnqueueArgs(
|
|
284
|
+
fn: FunctionReference<"action" | "mutation", FunctionVisibility>,
|
|
285
|
+
{ logLevel, maxParallelism }: Partial<Config>
|
|
286
|
+
) {
|
|
287
|
+
return {
|
|
288
|
+
fnHandle: await createFunctionHandle(fn),
|
|
289
|
+
fnName: getFunctionName(fn),
|
|
290
|
+
config: {
|
|
291
|
+
logLevel: logLevel ?? getDefaultLogLevel(),
|
|
292
|
+
maxParallelism: maxParallelism ?? DEFAULT_MAX_PARALLELISM,
|
|
293
|
+
},
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
|
|
267
297
|
function getRunAt(options?: SchedulerOptions): number {
|
|
268
298
|
if (!options) {
|
|
269
299
|
return Date.now();
|
|
@@ -47,13 +47,16 @@ export type Mounts = {
|
|
|
47
47
|
cancel: FunctionReference<
|
|
48
48
|
"mutation",
|
|
49
49
|
"public",
|
|
50
|
-
{ id: string; logLevel: "DEBUG" | "INFO" | "WARN" | "ERROR" },
|
|
50
|
+
{ id: string; logLevel: "DEBUG" | "INFO" | "REPORT" | "WARN" | "ERROR" },
|
|
51
51
|
any
|
|
52
52
|
>;
|
|
53
53
|
cancelAll: FunctionReference<
|
|
54
54
|
"mutation",
|
|
55
55
|
"public",
|
|
56
|
-
{
|
|
56
|
+
{
|
|
57
|
+
before?: number;
|
|
58
|
+
logLevel: "DEBUG" | "INFO" | "REPORT" | "WARN" | "ERROR";
|
|
59
|
+
},
|
|
57
60
|
any
|
|
58
61
|
>;
|
|
59
62
|
enqueue: FunctionReference<
|
|
@@ -61,7 +64,7 @@ export type Mounts = {
|
|
|
61
64
|
"public",
|
|
62
65
|
{
|
|
63
66
|
config: {
|
|
64
|
-
logLevel: "DEBUG" | "INFO" | "WARN" | "ERROR";
|
|
67
|
+
logLevel: "DEBUG" | "INFO" | "REPORT" | "WARN" | "ERROR";
|
|
65
68
|
maxParallelism: number;
|
|
66
69
|
};
|
|
67
70
|
fnArgs: any;
|
|
@@ -87,9 +90,6 @@ export type Mounts = {
|
|
|
87
90
|
| { state: "finished" }
|
|
88
91
|
>;
|
|
89
92
|
};
|
|
90
|
-
stats: {
|
|
91
|
-
queueLength: FunctionReference<"query", "public", {}, number>;
|
|
92
|
-
};
|
|
93
93
|
};
|
|
94
94
|
// For now fullApiWithMounts is only fullApi which provides
|
|
95
95
|
// jump-to-definition in component client code.
|