@convex-dev/workpool 0.2.19-alpha.2 → 0.2.19-alpha.3

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.
Files changed (194) hide show
  1. package/README.md +1 -0
  2. package/dist/{commonjs/client → client}/index.d.ts +13 -11
  3. package/dist/client/index.d.ts.map +1 -0
  4. package/dist/{commonjs/client → client}/index.js +6 -7
  5. package/dist/client/index.js.map +1 -0
  6. package/dist/{commonjs/client → client}/utils.d.ts +2 -2
  7. package/dist/client/utils.d.ts.map +1 -0
  8. package/dist/client/utils.js.map +1 -0
  9. package/dist/component/_generated/api.d.ts +151 -0
  10. package/dist/component/_generated/api.d.ts.map +1 -0
  11. package/dist/component/_generated/api.js.map +1 -0
  12. package/dist/component/_generated/dataModel.d.ts +60 -0
  13. package/dist/component/_generated/server.d.ts +149 -0
  14. package/dist/component/_generated/server.d.ts.map +1 -0
  15. package/dist/component/_generated/server.js.map +1 -0
  16. package/dist/{commonjs/component → component}/complete.d.ts +2 -2
  17. package/dist/component/complete.d.ts.map +1 -0
  18. package/dist/{commonjs/component → component}/complete.js +1 -1
  19. package/dist/component/complete.js.map +1 -0
  20. package/dist/component/convex.config.d.ts.map +1 -0
  21. package/dist/component/convex.config.js.map +1 -0
  22. package/dist/component/crons.d.ts.map +1 -0
  23. package/dist/{esm/component → component}/crons.js +4 -4
  24. package/dist/component/crons.js.map +1 -0
  25. package/dist/component/danger.d.ts.map +1 -0
  26. package/dist/component/danger.js.map +1 -0
  27. package/dist/{esm/component → component}/kick.d.ts +2 -2
  28. package/dist/component/kick.d.ts.map +1 -0
  29. package/dist/component/kick.js.map +1 -0
  30. package/dist/{esm/component → component}/lib.d.ts +1 -1
  31. package/dist/component/lib.d.ts.map +1 -0
  32. package/dist/{commonjs/component → component}/lib.js +3 -4
  33. package/dist/component/lib.js.map +1 -0
  34. package/dist/component/logging.d.ts.map +1 -0
  35. package/dist/component/logging.js.map +1 -0
  36. package/dist/{commonjs/component → component}/loop.d.ts +2 -2
  37. package/dist/component/loop.d.ts.map +1 -0
  38. package/dist/{commonjs/component → component}/loop.js +1 -1
  39. package/dist/component/loop.js.map +1 -0
  40. package/dist/{esm/component → component}/recovery.d.ts +2 -2
  41. package/dist/component/recovery.d.ts.map +1 -0
  42. package/dist/{commonjs/component → component}/recovery.js +1 -1
  43. package/dist/component/recovery.js.map +1 -0
  44. package/dist/{commonjs/component → component}/schema.d.ts.map +1 -1
  45. package/dist/component/schema.js.map +1 -0
  46. package/dist/component/shared.d.ts.map +1 -0
  47. package/dist/component/shared.js.map +1 -0
  48. package/dist/{esm/component → component}/stats.d.ts +4 -4
  49. package/dist/component/stats.d.ts.map +1 -0
  50. package/dist/{commonjs/component → component}/stats.js +0 -3
  51. package/dist/component/stats.js.map +1 -0
  52. package/dist/component/worker.d.ts.map +1 -0
  53. package/dist/component/worker.js.map +1 -0
  54. package/package.json +42 -39
  55. package/src/client/index.ts +32 -29
  56. package/src/client/utils.ts +7 -7
  57. package/src/component/_generated/api.d.ts +1 -0
  58. package/src/component/complete.test.ts +6 -6
  59. package/src/component/complete.ts +9 -5
  60. package/src/component/crons.ts +4 -4
  61. package/src/component/kick.test.ts +3 -3
  62. package/src/component/kick.ts +2 -2
  63. package/src/component/lib.test.ts +6 -6
  64. package/src/component/lib.ts +15 -5
  65. package/src/component/logging.test.ts +1 -1
  66. package/src/component/loop.test.ts +7 -7
  67. package/src/component/loop.ts +8 -8
  68. package/src/component/recovery.test.ts +9 -9
  69. package/src/component/recovery.ts +2 -2
  70. package/src/component/stats.test.ts +11 -11
  71. package/src/component/stats.ts +4 -7
  72. package/src/test.ts +3 -0
  73. package/dist/commonjs/client/index.d.ts.map +0 -1
  74. package/dist/commonjs/client/index.js.map +0 -1
  75. package/dist/commonjs/client/utils.d.ts.map +0 -1
  76. package/dist/commonjs/client/utils.js.map +0 -1
  77. package/dist/commonjs/component/_generated/api.d.ts +0 -12
  78. package/dist/commonjs/component/_generated/api.d.ts.map +0 -1
  79. package/dist/commonjs/component/_generated/api.js.map +0 -1
  80. package/dist/commonjs/component/_generated/server.d.ts +0 -64
  81. package/dist/commonjs/component/_generated/server.d.ts.map +0 -1
  82. package/dist/commonjs/component/_generated/server.js.map +0 -1
  83. package/dist/commonjs/component/complete.d.ts.map +0 -1
  84. package/dist/commonjs/component/complete.js.map +0 -1
  85. package/dist/commonjs/component/convex.config.d.ts.map +0 -1
  86. package/dist/commonjs/component/convex.config.js.map +0 -1
  87. package/dist/commonjs/component/crons.d.ts.map +0 -1
  88. package/dist/commonjs/component/crons.js +0 -61
  89. package/dist/commonjs/component/crons.js.map +0 -1
  90. package/dist/commonjs/component/danger.d.ts.map +0 -1
  91. package/dist/commonjs/component/danger.js.map +0 -1
  92. package/dist/commonjs/component/kick.d.ts +0 -9
  93. package/dist/commonjs/component/kick.d.ts.map +0 -1
  94. package/dist/commonjs/component/kick.js.map +0 -1
  95. package/dist/commonjs/component/lib.d.ts +0 -79
  96. package/dist/commonjs/component/lib.d.ts.map +0 -1
  97. package/dist/commonjs/component/lib.js.map +0 -1
  98. package/dist/commonjs/component/logging.d.ts.map +0 -1
  99. package/dist/commonjs/component/logging.js.map +0 -1
  100. package/dist/commonjs/component/loop.d.ts.map +0 -1
  101. package/dist/commonjs/component/loop.js.map +0 -1
  102. package/dist/commonjs/component/recovery.d.ts +0 -53
  103. package/dist/commonjs/component/recovery.d.ts.map +0 -1
  104. package/dist/commonjs/component/recovery.js.map +0 -1
  105. package/dist/commonjs/component/schema.js.map +0 -1
  106. package/dist/commonjs/component/shared.d.ts.map +0 -1
  107. package/dist/commonjs/component/shared.js.map +0 -1
  108. package/dist/commonjs/component/stats.d.ts +0 -45
  109. package/dist/commonjs/component/stats.d.ts.map +0 -1
  110. package/dist/commonjs/component/stats.js.map +0 -1
  111. package/dist/commonjs/component/worker.d.ts.map +0 -1
  112. package/dist/commonjs/component/worker.js.map +0 -1
  113. package/dist/commonjs/package.json +0 -3
  114. package/dist/esm/client/index.d.ts +0 -429
  115. package/dist/esm/client/index.d.ts.map +0 -1
  116. package/dist/esm/client/index.js +0 -317
  117. package/dist/esm/client/index.js.map +0 -1
  118. package/dist/esm/client/utils.d.ts +0 -16
  119. package/dist/esm/client/utils.d.ts.map +0 -1
  120. package/dist/esm/client/utils.js +0 -9
  121. package/dist/esm/client/utils.js.map +0 -1
  122. package/dist/esm/component/_generated/api.d.ts +0 -12
  123. package/dist/esm/component/_generated/api.d.ts.map +0 -1
  124. package/dist/esm/component/_generated/api.js +0 -22
  125. package/dist/esm/component/_generated/api.js.map +0 -1
  126. package/dist/esm/component/_generated/server.d.ts +0 -64
  127. package/dist/esm/component/_generated/server.d.ts.map +0 -1
  128. package/dist/esm/component/_generated/server.js +0 -74
  129. package/dist/esm/component/_generated/server.js.map +0 -1
  130. package/dist/esm/component/complete.d.ts +0 -89
  131. package/dist/esm/component/complete.d.ts.map +0 -1
  132. package/dist/esm/component/complete.js +0 -88
  133. package/dist/esm/component/complete.js.map +0 -1
  134. package/dist/esm/component/convex.config.d.ts +0 -3
  135. package/dist/esm/component/convex.config.d.ts.map +0 -1
  136. package/dist/esm/component/convex.config.js +0 -4
  137. package/dist/esm/component/convex.config.js.map +0 -1
  138. package/dist/esm/component/crons.d.ts +0 -4
  139. package/dist/esm/component/crons.d.ts.map +0 -1
  140. package/dist/esm/component/crons.js.map +0 -1
  141. package/dist/esm/component/danger.d.ts +0 -11
  142. package/dist/esm/component/danger.d.ts.map +0 -1
  143. package/dist/esm/component/danger.js +0 -92
  144. package/dist/esm/component/danger.js.map +0 -1
  145. package/dist/esm/component/kick.d.ts.map +0 -1
  146. package/dist/esm/component/kick.js +0 -102
  147. package/dist/esm/component/kick.js.map +0 -1
  148. package/dist/esm/component/lib.d.ts.map +0 -1
  149. package/dist/esm/component/lib.js +0 -179
  150. package/dist/esm/component/lib.js.map +0 -1
  151. package/dist/esm/component/logging.d.ts +0 -16
  152. package/dist/esm/component/logging.d.ts.map +0 -1
  153. package/dist/esm/component/logging.js +0 -71
  154. package/dist/esm/component/logging.js.map +0 -1
  155. package/dist/esm/component/loop.d.ts +0 -14
  156. package/dist/esm/component/loop.d.ts.map +0 -1
  157. package/dist/esm/component/loop.js +0 -503
  158. package/dist/esm/component/loop.js.map +0 -1
  159. package/dist/esm/component/recovery.d.ts.map +0 -1
  160. package/dist/esm/component/recovery.js +0 -97
  161. package/dist/esm/component/recovery.js.map +0 -1
  162. package/dist/esm/component/schema.d.ts +0 -228
  163. package/dist/esm/component/schema.d.ts.map +0 -1
  164. package/dist/esm/component/schema.js +0 -79
  165. package/dist/esm/component/schema.js.map +0 -1
  166. package/dist/esm/component/shared.d.ts +0 -140
  167. package/dist/esm/component/shared.d.ts.map +0 -1
  168. package/dist/esm/component/shared.js +0 -79
  169. package/dist/esm/component/shared.js.map +0 -1
  170. package/dist/esm/component/stats.d.ts.map +0 -1
  171. package/dist/esm/component/stats.js +0 -129
  172. package/dist/esm/component/stats.js.map +0 -1
  173. package/dist/esm/component/worker.d.ts +0 -16
  174. package/dist/esm/component/worker.d.ts.map +0 -1
  175. package/dist/esm/component/worker.js +0 -76
  176. package/dist/esm/component/worker.js.map +0 -1
  177. package/dist/esm/package.json +0 -3
  178. /package/dist/{commonjs/client → client}/utils.js +0 -0
  179. /package/dist/{commonjs/component → component}/_generated/api.js +0 -0
  180. /package/dist/{commonjs/component → component}/_generated/server.js +0 -0
  181. /package/dist/{commonjs/component → component}/convex.config.d.ts +0 -0
  182. /package/dist/{commonjs/component → component}/convex.config.js +0 -0
  183. /package/dist/{commonjs/component → component}/crons.d.ts +0 -0
  184. /package/dist/{commonjs/component → component}/danger.d.ts +0 -0
  185. /package/dist/{commonjs/component → component}/danger.js +0 -0
  186. /package/dist/{commonjs/component → component}/kick.js +0 -0
  187. /package/dist/{commonjs/component → component}/logging.d.ts +0 -0
  188. /package/dist/{commonjs/component → component}/logging.js +0 -0
  189. /package/dist/{commonjs/component → component}/schema.d.ts +0 -0
  190. /package/dist/{commonjs/component → component}/schema.js +0 -0
  191. /package/dist/{commonjs/component → component}/shared.d.ts +0 -0
  192. /package/dist/{commonjs/component → component}/shared.js +0 -0
  193. /package/dist/{commonjs/component → component}/worker.d.ts +0 -0
  194. /package/dist/{commonjs/component → component}/worker.js +0 -0
@@ -1,97 +0,0 @@
1
- import { v } from "convex/values";
2
- import { internalMutation } from "./_generated/server.js";
3
- import { completeHandler } from "./complete.js";
4
- import { createLogger } from "./logging.js";
5
- const recoveryArgs = v.object({
6
- jobs: v.array(v.object({
7
- scheduledId: v.id("_scheduled_functions"),
8
- workId: v.id("work"),
9
- attempt: v.number(),
10
- started: v.number(),
11
- })),
12
- });
13
- /**
14
- * This can run when things fail because of server failures / restarts, or when
15
- * the user cancels scheduled jobs (from the dashboard).
16
- * Possible states it could be in at the moment this executes:
17
- * - in internalState.running and complete was never called
18
- * -> we should call completeHandler with failure.
19
- * - complete already called, no action needed (only possible for actions):
20
- * - In pendingCompletion still and internalState.running.
21
- * -> check for pendingCompletion.
22
- * - pendingCompletion already processed.
23
- * - No retry: work was deleted, not in internalState.running.
24
- * -> check for work.
25
- * - Retry: attempts will mismatch
26
- * -> check work.attempts
27
- */
28
- export const recover = internalMutation({
29
- args: recoveryArgs,
30
- handler: recoveryHandler,
31
- });
32
- // only exported for testing
33
- export async function recoveryHandler(ctx, { jobs }) {
34
- const globals = await ctx.db.query("globals").unique();
35
- const console = createLogger(globals?.logLevel);
36
- const toComplete = [];
37
- for (let i = 0; i < jobs.length; i++) {
38
- const job = jobs[i];
39
- const preamble = `[recovery] Scheduled job ${job.scheduledId} for work ${job.workId}`;
40
- const pendingCompletion = await ctx.db
41
- .query("pendingCompletion")
42
- .withIndex("workId", (q) => q.eq("workId", job.workId))
43
- .first();
44
- if (pendingCompletion) {
45
- // Completion already pending, no need to do anything.
46
- console.debug(`${preamble} already in pendingCompletion, skipping`);
47
- continue;
48
- }
49
- const work = await ctx.db.get(job.workId);
50
- if (work === null) {
51
- // Completion already executed w/o retries, no need to do anything.
52
- console.warn(`${preamble} work not found, skipping`);
53
- continue;
54
- }
55
- if (work.attempts !== job.attempt) {
56
- // Retry already started, no need to do anything.
57
- console.warn(`${preamble} attempts mismatch, skipping`);
58
- continue;
59
- }
60
- const scheduled = await ctx.db.system.get(job.scheduledId);
61
- if (scheduled === null) {
62
- console.warn(`${preamble} not found in _scheduled_functions`);
63
- toComplete.push({
64
- workId: job.workId,
65
- runResult: { kind: "failed", error: `Scheduled job not found` },
66
- attempt: job.attempt,
67
- });
68
- continue;
69
- }
70
- // This will find everything that timed out, failed ungracefully, was
71
- // canceled, or succeeded without a return value.
72
- switch (scheduled.state.kind) {
73
- case "failed": {
74
- console.debug(`${preamble} failed and detected in recovery`);
75
- toComplete.push({
76
- workId: job.workId,
77
- runResult: scheduled.state,
78
- attempt: job.attempt,
79
- });
80
- break;
81
- }
82
- case "canceled": {
83
- console.debug(`${preamble} was canceled and detected in recovery`);
84
- toComplete.push({
85
- workId: job.workId,
86
- runResult: { kind: "failed", error: "Canceled via scheduler" },
87
- attempt: job.attempt,
88
- });
89
- break;
90
- }
91
- }
92
- }
93
- if (toComplete.length > 0) {
94
- await completeHandler(ctx, { jobs: toComplete });
95
- }
96
- }
97
- //# sourceMappingURL=recovery.js.map
@@ -1 +0,0 @@
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,E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;gBAChB,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;YACR,CAAC;QACH,CAAC;IACH,CAAC;IACD,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,eAAe,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;IACnD,CAAC;AACH,CAAC"}
@@ -1,228 +0,0 @@
1
- declare const _default: import("convex/server").SchemaDefinition<{
2
- globals: import("convex/server").TableDefinition<import("convex/values").VObject<{
3
- maxParallelism: number;
4
- logLevel: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
5
- }, {
6
- maxParallelism: import("convex/values").VFloat64<number, "required">;
7
- logLevel: import("convex/values").VUnion<"DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR", [import("convex/values").VLiteral<"DEBUG", "required">, import("convex/values").VLiteral<"TRACE", "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
- }, "required", "maxParallelism" | "logLevel">, {}, {}, {}>;
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
- };
18
- running: {
19
- workId: import("convex/values").GenericId<"work">;
20
- scheduledId: import("convex/values").GenericId<"_scheduled_functions">;
21
- started: number;
22
- }[];
23
- lastRecovery: bigint;
24
- generation: bigint;
25
- segmentCursors: {
26
- incoming: bigint;
27
- completion: bigint;
28
- cancelation: bigint;
29
- };
30
- }, {
31
- generation: import("convex/values").VInt64<bigint, "required">;
32
- segmentCursors: import("convex/values").VObject<{
33
- incoming: bigint;
34
- completion: bigint;
35
- cancelation: bigint;
36
- }, {
37
- incoming: import("convex/values").VInt64<bigint, "required">;
38
- completion: import("convex/values").VInt64<bigint, "required">;
39
- cancelation: import("convex/values").VInt64<bigint, "required">;
40
- }, "required", "incoming" | "completion" | "cancelation">;
41
- lastRecovery: import("convex/values").VInt64<bigint, "required">;
42
- report: import("convex/values").VObject<{
43
- failed: number;
44
- canceled: number;
45
- completed: number;
46
- succeeded: number;
47
- retries: number;
48
- lastReportTs: number;
49
- }, {
50
- completed: import("convex/values").VFloat64<number, "required">;
51
- succeeded: import("convex/values").VFloat64<number, "required">;
52
- failed: import("convex/values").VFloat64<number, "required">;
53
- retries: import("convex/values").VFloat64<number, "required">;
54
- canceled: import("convex/values").VFloat64<number, "required">;
55
- lastReportTs: import("convex/values").VFloat64<number, "required">;
56
- }, "required", "failed" | "canceled" | "completed" | "succeeded" | "retries" | "lastReportTs">;
57
- running: import("convex/values").VArray<{
58
- workId: import("convex/values").GenericId<"work">;
59
- scheduledId: import("convex/values").GenericId<"_scheduled_functions">;
60
- started: number;
61
- }[], import("convex/values").VObject<{
62
- workId: import("convex/values").GenericId<"work">;
63
- scheduledId: import("convex/values").GenericId<"_scheduled_functions">;
64
- started: number;
65
- }, {
66
- workId: import("convex/values").VId<import("convex/values").GenericId<"work">, "required">;
67
- scheduledId: import("convex/values").VId<import("convex/values").GenericId<"_scheduled_functions">, "required">;
68
- started: import("convex/values").VFloat64<number, "required">;
69
- }, "required", "workId" | "scheduledId" | "started">, "required">;
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
- runStatus: import("convex/server").TableDefinition<import("convex/values").VObject<{
72
- state: {
73
- kind: "running";
74
- } | {
75
- kind: "scheduled";
76
- generation: bigint;
77
- scheduledId: import("convex/values").GenericId<"_scheduled_functions">;
78
- segment: bigint;
79
- saturated: boolean;
80
- } | {
81
- kind: "idle";
82
- generation: bigint;
83
- };
84
- }, {
85
- state: import("convex/values").VUnion<{
86
- kind: "running";
87
- } | {
88
- kind: "scheduled";
89
- generation: bigint;
90
- scheduledId: import("convex/values").GenericId<"_scheduled_functions">;
91
- segment: bigint;
92
- saturated: boolean;
93
- } | {
94
- kind: "idle";
95
- generation: bigint;
96
- }, [import("convex/values").VObject<{
97
- kind: "running";
98
- }, {
99
- kind: import("convex/values").VLiteral<"running", "required">;
100
- }, "required", "kind">, import("convex/values").VObject<{
101
- kind: "scheduled";
102
- generation: bigint;
103
- scheduledId: import("convex/values").GenericId<"_scheduled_functions">;
104
- segment: bigint;
105
- saturated: boolean;
106
- }, {
107
- kind: import("convex/values").VLiteral<"scheduled", "required">;
108
- segment: import("convex/values").VInt64<bigint, "required">;
109
- scheduledId: import("convex/values").VId<import("convex/values").GenericId<"_scheduled_functions">, "required">;
110
- saturated: import("convex/values").VBoolean<boolean, "required">;
111
- generation: import("convex/values").VInt64<bigint, "required">;
112
- }, "required", "kind" | "generation" | "scheduledId" | "segment" | "saturated">, import("convex/values").VObject<{
113
- kind: "idle";
114
- generation: bigint;
115
- }, {
116
- kind: import("convex/values").VLiteral<"idle", "required">;
117
- generation: import("convex/values").VInt64<bigint, "required">;
118
- }, "required", "kind" | "generation">], "required", "kind" | "generation" | "scheduledId" | "segment" | "saturated">;
119
- }, "required", "state" | "state.kind" | "state.generation" | "state.scheduledId" | "state.segment" | "state.saturated">, {}, {}, {}>;
120
- work: import("convex/server").TableDefinition<import("convex/values").VObject<{
121
- canceled?: boolean | undefined;
122
- onComplete?: {
123
- context?: any;
124
- fnHandle: string;
125
- } | undefined;
126
- retryBehavior?: {
127
- maxAttempts: number;
128
- initialBackoffMs: number;
129
- base: number;
130
- } | undefined;
131
- fnHandle: string;
132
- fnType: "action" | "mutation" | "query";
133
- fnName: string;
134
- fnArgs: any;
135
- attempts: number;
136
- }, {
137
- fnType: import("convex/values").VUnion<"action" | "mutation" | "query", [import("convex/values").VLiteral<"action", "required">, import("convex/values").VLiteral<"mutation", "required">, import("convex/values").VLiteral<"query", "required">], "required", never>;
138
- fnHandle: import("convex/values").VString<string, "required">;
139
- fnName: import("convex/values").VString<string, "required">;
140
- fnArgs: import("convex/values").VAny<any, "required", string>;
141
- attempts: import("convex/values").VFloat64<number, "required">;
142
- onComplete: import("convex/values").VObject<{
143
- context?: any;
144
- fnHandle: string;
145
- } | undefined, {
146
- fnHandle: import("convex/values").VString<string, "required">;
147
- context: import("convex/values").VAny<any, "optional", string>;
148
- }, "optional", "fnHandle" | "context" | `context.${string}`>;
149
- retryBehavior: import("convex/values").VObject<{
150
- maxAttempts: number;
151
- initialBackoffMs: number;
152
- base: number;
153
- } | undefined, {
154
- maxAttempts: import("convex/values").VFloat64<number, "required">;
155
- initialBackoffMs: import("convex/values").VFloat64<number, "required">;
156
- base: import("convex/values").VFloat64<number, "required">;
157
- }, "optional", "maxAttempts" | "initialBackoffMs" | "base">;
158
- canceled: import("convex/values").VBoolean<boolean | undefined, "optional">;
159
- }, "required", "canceled" | "fnHandle" | "fnType" | "fnName" | "fnArgs" | "attempts" | "onComplete" | "retryBehavior" | `fnArgs.${string}` | "onComplete.fnHandle" | "onComplete.context" | `onComplete.context.${string}` | "retryBehavior.maxAttempts" | "retryBehavior.initialBackoffMs" | "retryBehavior.base">, {}, {}, {}>;
160
- pendingStart: import("convex/server").TableDefinition<import("convex/values").VObject<{
161
- workId: import("convex/values").GenericId<"work">;
162
- segment: bigint;
163
- }, {
164
- workId: import("convex/values").VId<import("convex/values").GenericId<"work">, "required">;
165
- segment: import("convex/values").VInt64<bigint, "required">;
166
- }, "required", "workId" | "segment">, {
167
- workId: ["workId", "_creationTime"];
168
- segment: ["segment", "_creationTime"];
169
- }, {}, {}>;
170
- pendingCompletion: import("convex/server").TableDefinition<import("convex/values").VObject<{
171
- workId: import("convex/values").GenericId<"work">;
172
- segment: bigint;
173
- runResult: {
174
- kind: "success";
175
- returnValue: any;
176
- } | {
177
- kind: "failed";
178
- error: string;
179
- } | {
180
- kind: "canceled";
181
- };
182
- retry: boolean;
183
- }, {
184
- segment: import("convex/values").VInt64<bigint, "required">;
185
- runResult: import("convex/values").VUnion<{
186
- kind: "success";
187
- returnValue: any;
188
- } | {
189
- kind: "failed";
190
- error: string;
191
- } | {
192
- kind: "canceled";
193
- }, [import("convex/values").VObject<{
194
- kind: "success";
195
- returnValue: any;
196
- }, {
197
- kind: import("convex/values").VLiteral<"success", "required">;
198
- returnValue: import("convex/values").VAny<any, "required", string>;
199
- }, "required", "kind" | "returnValue" | `returnValue.${string}`>, import("convex/values").VObject<{
200
- kind: "failed";
201
- error: string;
202
- }, {
203
- kind: import("convex/values").VLiteral<"failed", "required">;
204
- error: import("convex/values").VString<string, "required">;
205
- }, "required", "kind" | "error">, import("convex/values").VObject<{
206
- kind: "canceled";
207
- }, {
208
- kind: import("convex/values").VLiteral<"canceled", "required">;
209
- }, "required", "kind">], "required", "kind" | "returnValue" | `returnValue.${string}` | "error">;
210
- workId: import("convex/values").VId<import("convex/values").GenericId<"work">, "required">;
211
- retry: import("convex/values").VBoolean<boolean, "required">;
212
- }, "required", "workId" | "segment" | "runResult" | "retry" | "runResult.kind" | "runResult.returnValue" | `runResult.returnValue.${string}` | "runResult.error">, {
213
- workId: ["workId", "_creationTime"];
214
- segment: ["segment", "_creationTime"];
215
- }, {}, {}>;
216
- pendingCancelation: import("convex/server").TableDefinition<import("convex/values").VObject<{
217
- workId: import("convex/values").GenericId<"work">;
218
- segment: bigint;
219
- }, {
220
- segment: import("convex/values").VInt64<bigint, "required">;
221
- workId: import("convex/values").VId<import("convex/values").GenericId<"work">, "required">;
222
- }, "required", "workId" | "segment">, {
223
- workId: ["workId", "_creationTime"];
224
- segment: ["segment", "_creationTime"];
225
- }, {}, {}>;
226
- }, true>;
227
- export default _default;
228
- //# sourceMappingURL=schema.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/component/schema.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,wBAmFG"}
@@ -1,79 +0,0 @@
1
- import { defineSchema, defineTable } from "convex/server";
2
- import { v } from "convex/values";
3
- import { fnType, config, onComplete, retryBehavior, vResultValidator, } from "./shared.js";
4
- // Represents a slice of time to process work.
5
- const segment = v.int64();
6
- export default defineSchema({
7
- // Written from kickLoop, read everywhere.
8
- globals: defineTable(config),
9
- // Singleton, only read & written by `main`.
10
- internalState: defineTable({
11
- // Ensure that only one main is running at a time.
12
- generation: v.int64(),
13
- segmentCursors: v.object({
14
- incoming: segment,
15
- completion: segment,
16
- cancelation: segment,
17
- }),
18
- lastRecovery: segment,
19
- report: v.object({
20
- completed: v.number(), // finished running, counts retries & failures
21
- succeeded: v.number(), // finished successfully, regardless of retries
22
- failed: v.number(), // failed after all retries
23
- retries: v.number(), // failure that turned into a retry
24
- canceled: v.number(), // cancelations processed
25
- lastReportTs: v.number(),
26
- }),
27
- running: v.array(v.object({
28
- workId: v.id("work"),
29
- scheduledId: v.id("_scheduled_functions"),
30
- started: v.number(),
31
- })),
32
- }),
33
- // Singleton, written by `updateRunStatus` when running, by client or worker otherwise.
34
- // Safe to read from kickLoop, since it should update infrequently.
35
- runStatus: defineTable({
36
- state: v.union(v.object({ kind: v.literal("running") }), v.object({
37
- kind: v.literal("scheduled"),
38
- segment,
39
- scheduledId: v.id("_scheduled_functions"),
40
- saturated: v.boolean(),
41
- generation: v.int64(),
42
- }), v.object({ kind: v.literal("idle"), generation: v.int64() })),
43
- }),
44
- // Written on enqueue. Deleted by `complete` for success, failure, canceled.
45
- work: defineTable({
46
- fnType,
47
- fnHandle: v.string(),
48
- fnName: v.string(),
49
- fnArgs: v.any(),
50
- attempts: v.number(), // number of completed attempts
51
- onComplete: v.optional(onComplete),
52
- retryBehavior: v.optional(retryBehavior),
53
- canceled: v.optional(v.boolean()),
54
- }),
55
- // Written on enqueue & rescheduled for retry, read & deleted by `main`.
56
- pendingStart: defineTable({
57
- workId: v.id("work"),
58
- segment,
59
- })
60
- .index("workId", ["workId"])
61
- .index("segment", ["segment"]),
62
- // Written by complete, read & deleted by `main`.
63
- pendingCompletion: defineTable({
64
- segment,
65
- runResult: vResultValidator,
66
- workId: v.id("work"),
67
- retry: v.boolean(),
68
- })
69
- .index("workId", ["workId"])
70
- .index("segment", ["segment"]),
71
- // Written on cancelation, read & deleted by `main`.
72
- pendingCancelation: defineTable({
73
- segment,
74
- workId: v.id("work"),
75
- })
76
- .index("workId", ["workId"])
77
- .index("segment", ["segment"]),
78
- });
79
- //# sourceMappingURL=schema.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/component/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EACL,MAAM,EACN,MAAM,EACN,UAAU,EACV,aAAa,EACb,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAErB,8CAA8C;AAC9C,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;AAE1B,eAAe,YAAY,CAAC;IAC1B,0CAA0C;IAC1C,OAAO,EAAE,WAAW,CAAC,MA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C,oDAAoD;IACpD,kBAAkB,EAAE,WAAW,CAAC;QAC9B,OAAO;QACP,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC;KACrB,CAAC;SACC,KAAK,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC;SAC3B,KAAK,CAAC,SAAS,EAAE,CAAC,SAAS,CAAC,CAAC;CACjC,CAAC,CAAC"}
@@ -1,140 +0,0 @@
1
- import type { Infer } from "convex/values";
2
- import { type Logger } from "./logging.js";
3
- export declare const fnType: import("convex/values").VUnion<"action" | "mutation" | "query", [import("convex/values").VLiteral<"action", "required">, import("convex/values").VLiteral<"mutation", "required">, import("convex/values").VLiteral<"query", "required">], "required", never>;
4
- export declare const DEFAULT_MAX_PARALLELISM = 10;
5
- export declare const SECOND = 1000;
6
- export declare const MINUTE: number;
7
- export declare const HOUR: number;
8
- export declare const DAY: number;
9
- export declare const YEAR: number;
10
- export declare function toSegment(ms: number): bigint;
11
- export declare function getCurrentSegment(): bigint;
12
- export declare function getNextSegment(): bigint;
13
- export declare function fromSegment(segment: bigint): number;
14
- export declare const config: import("convex/values").VObject<{
15
- maxParallelism: number;
16
- logLevel: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
17
- }, {
18
- maxParallelism: import("convex/values").VFloat64<number, "required">;
19
- logLevel: import("convex/values").VUnion<"DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR", [import("convex/values").VLiteral<"DEBUG", "required">, import("convex/values").VLiteral<"TRACE", "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>;
20
- }, "required", "maxParallelism" | "logLevel">;
21
- export type Config = Infer<typeof config>;
22
- export declare const retryBehavior: import("convex/values").VObject<{
23
- maxAttempts: number;
24
- initialBackoffMs: number;
25
- base: number;
26
- }, {
27
- maxAttempts: import("convex/values").VFloat64<number, "required">;
28
- initialBackoffMs: import("convex/values").VFloat64<number, "required">;
29
- base: import("convex/values").VFloat64<number, "required">;
30
- }, "required", "maxAttempts" | "initialBackoffMs" | "base">;
31
- export type RetryBehavior = {
32
- /**
33
- * The maximum number of attempts to make. 2 means one retry.
34
- */
35
- maxAttempts: number;
36
- /**
37
- * The initial backoff time in milliseconds. 100 means wait 100ms before the
38
- * first retry.
39
- */
40
- initialBackoffMs: number;
41
- /**
42
- * The base for the backoff. 2 means double the backoff each time.
43
- * e.g. if the initial backoff is 100ms, and the base is 2, then the first
44
- * retry will wait 200ms, the second will wait 400ms, etc.
45
- */
46
- base: number;
47
- };
48
- export declare const vResultValidator: import("convex/values").VUnion<{
49
- kind: "success";
50
- returnValue: any;
51
- } | {
52
- kind: "failed";
53
- error: string;
54
- } | {
55
- kind: "canceled";
56
- }, [import("convex/values").VObject<{
57
- kind: "success";
58
- returnValue: any;
59
- }, {
60
- kind: import("convex/values").VLiteral<"success", "required">;
61
- returnValue: import("convex/values").VAny<any, "required", string>;
62
- }, "required", "kind" | "returnValue" | `returnValue.${string}`>, import("convex/values").VObject<{
63
- kind: "failed";
64
- error: string;
65
- }, {
66
- kind: import("convex/values").VLiteral<"failed", "required">;
67
- error: import("convex/values").VString<string, "required">;
68
- }, "required", "kind" | "error">, import("convex/values").VObject<{
69
- kind: "canceled";
70
- }, {
71
- kind: import("convex/values").VLiteral<"canceled", "required">;
72
- }, "required", "kind">], "required", "kind" | "returnValue" | `returnValue.${string}` | "error">;
73
- export type RunResult = Infer<typeof vResultValidator>;
74
- export declare const onComplete: import("convex/values").VObject<{
75
- context?: any;
76
- fnHandle: string;
77
- }, {
78
- fnHandle: import("convex/values").VString<string, "required">;
79
- context: import("convex/values").VAny<any, "optional", string>;
80
- }, "required", "fnHandle" | "context" | `context.${string}`>;
81
- export type OnComplete = Infer<typeof onComplete>;
82
- export type OnCompleteArgs = {
83
- /**
84
- * The ID of the work that completed.
85
- */
86
- workId: string;
87
- /**
88
- * The context object passed when enqueuing the work.
89
- * Useful for passing data from the enqueue site to the onComplete site.
90
- */
91
- context: unknown;
92
- /**
93
- * The result of the run that completed.
94
- */
95
- result: RunResult;
96
- };
97
- export declare const status: import("convex/values").VUnion<{
98
- state: "pending";
99
- previousAttempts: number;
100
- } | {
101
- state: "running";
102
- previousAttempts: number;
103
- } | {
104
- state: "finished";
105
- }, [import("convex/values").VUnion<{
106
- state: "pending";
107
- previousAttempts: number;
108
- } | {
109
- state: "running";
110
- previousAttempts: number;
111
- } | {
112
- state: "finished";
113
- }, [import("convex/values").VObject<{
114
- state: "pending";
115
- previousAttempts: number;
116
- }, {
117
- state: import("convex/values").VLiteral<"pending", "required">;
118
- previousAttempts: import("convex/values").VFloat64<number, "required">;
119
- }, "required", "state" | "previousAttempts">, import("convex/values").VObject<{
120
- state: "running";
121
- previousAttempts: number;
122
- }, {
123
- state: import("convex/values").VLiteral<"running", "required">;
124
- previousAttempts: import("convex/values").VFloat64<number, "required">;
125
- }, "required", "state" | "previousAttempts">, import("convex/values").VObject<{
126
- state: "finished";
127
- }, {
128
- state: import("convex/values").VLiteral<"finished", "required">;
129
- }, "required", "state">], "required", "state" | "previousAttempts">], "required", "state" | "previousAttempts">;
130
- export type Status = Infer<typeof status>;
131
- export declare function boundScheduledTime(ms: number, console: Logger): number;
132
- /**
133
- * Returns the smaller of two bigint values.
134
- */
135
- export declare function min<T extends bigint>(a: T, b: T): T;
136
- /**
137
- * Returns the larger of two bigint values.
138
- */
139
- export declare function max<T extends bigint>(a: T, b: T): T;
140
- //# sourceMappingURL=shared.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/component/shared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAG3C,OAAO,EAAE,KAAK,MAAM,EAAY,MAAM,cAAc,CAAC;AAErD,eAAO,MAAM,MAAM,+PAIlB,CAAC;AAEF,eAAO,MA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AC;AACF,MAAM,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,MAAM,CAAC,CAAC;AAE1C,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAatE;AAED;;GAEG;AACH,wBAAgB,GAAG,CAAC,CAAC,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"}
@@ -1,79 +0,0 @@
1
- import { v } from "convex/values";
2
- import { logLevel } from "./logging.js";
3
- export const fnType = v.union(v.literal("action"), v.literal("mutation"), v.literal("query"));
4
- export const DEFAULT_MAX_PARALLELISM = 10;
5
- const SEGMENT_MS = 100;
6
- export const SECOND = 1000;
7
- export const MINUTE = 60 * SECOND;
8
- export const HOUR = 60 * MINUTE;
9
- export const DAY = 24 * HOUR;
10
- export const YEAR = 365 * DAY;
11
- export function toSegment(ms) {
12
- return BigInt(Math.floor(ms / SEGMENT_MS));
13
- }
14
- export function getCurrentSegment() {
15
- return toSegment(Date.now());
16
- }
17
- export function getNextSegment() {
18
- return toSegment(Date.now()) + 1n;
19
- }
20
- export function fromSegment(segment) {
21
- return Number(segment) * SEGMENT_MS;
22
- }
23
- export const config = v.object({
24
- maxParallelism: v.number(),
25
- logLevel,
26
- });
27
- export const retryBehavior = v.object({
28
- maxAttempts: v.number(),
29
- initialBackoffMs: v.number(),
30
- base: v.number(),
31
- });
32
- // This ensures that the type satisfies the schema.
33
- const _ = {};
34
- export const vResultValidator = v.union(v.object({
35
- kind: v.literal("success"),
36
- returnValue: v.any(),
37
- }), v.object({
38
- kind: v.literal("failed"),
39
- error: v.string(),
40
- }), v.object({
41
- kind: v.literal("canceled"),
42
- }));
43
- export const onComplete = v.object({
44
- fnHandle: v.string(), // mutation
45
- context: v.optional(v.any()),
46
- });
47
- export const status = v.union(v.union(v.object({
48
- state: v.literal("pending"),
49
- previousAttempts: v.number(),
50
- }), v.object({
51
- state: v.literal("running"),
52
- previousAttempts: v.number(),
53
- }), v.object({
54
- state: v.literal("finished"),
55
- })));
56
- export function boundScheduledTime(ms, console) {
57
- if (ms < Date.now() - YEAR) {
58
- console.error("scheduled time is too old, defaulting to now", ms);
59
- return Date.now();
60
- }
61
- if (ms > Date.now() + 4 * YEAR) {
62
- console.error("scheduled time is too far in the future, defaulting to 1 year from now", ms);
63
- return Date.now() + YEAR;
64
- }
65
- return ms;
66
- }
67
- /**
68
- * Returns the smaller of two bigint values.
69
- */
70
- export function min(a, b) {
71
- return a > b ? b : a;
72
- }
73
- /**
74
- * Returns the larger of two bigint values.
75
- */
76
- export function max(a, b) {
77
- return a < b ? b : a;
78
- }
79
- //# sourceMappingURL=shared.js.map