convex-batch-processor 1.0.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/LICENSE +21 -0
- package/README.md +337 -0
- package/dist/client/index.d.ts +194 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +75 -0
- package/dist/client/index.js.map +1 -0
- package/dist/component/_generated/api.d.ts +34 -0
- package/dist/component/_generated/api.d.ts.map +1 -0
- package/dist/component/_generated/api.js +31 -0
- package/dist/component/_generated/api.js.map +1 -0
- package/dist/component/_generated/component.d.ts +77 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +11 -0
- package/dist/component/_generated/component.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +46 -0
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +11 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +121 -0
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/dist/component/_generated/server.js +78 -0
- package/dist/component/_generated/server.js.map +1 -0
- package/dist/component/convex.config.d.ts +3 -0
- package/dist/component/convex.config.d.ts.map +1 -0
- package/dist/component/convex.config.js +3 -0
- package/dist/component/convex.config.js.map +1 -0
- package/dist/component/lib.d.ts +261 -0
- package/dist/component/lib.d.ts.map +1 -0
- package/dist/component/lib.js +629 -0
- package/dist/component/lib.js.map +1 -0
- package/dist/component/schema.d.ts +100 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +49 -0
- package/dist/component/schema.js.map +1 -0
- package/package.json +63 -0
- package/src/client/index.test.ts +121 -0
- package/src/client/index.ts +308 -0
- package/src/component/_generated/api.ts +50 -0
- package/src/component/_generated/component.ts +133 -0
- package/src/component/_generated/dataModel.ts +60 -0
- package/src/component/_generated/server.ts +156 -0
- package/src/component/convex.config.ts +3 -0
- package/src/component/lib.ts +792 -0
- package/src/component/schema.ts +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Blocksight
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
# convex-batch-processor
|
|
2
|
+
|
|
3
|
+
A Convex component for batch processing:
|
|
4
|
+
|
|
5
|
+
1. **Batch Accumulator** - Collect items and flush when reaching size threshold or time interval
|
|
6
|
+
2. **Table Iterator** - Process large tables in controlled batch sizes with pause/resume support
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install convex-batch-processor
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Setup
|
|
15
|
+
|
|
16
|
+
Add the component to your Convex app:
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
// convex/convex.config.ts
|
|
20
|
+
import { defineApp } from "convex/server";
|
|
21
|
+
import batchProcessor from "convex-batch-processor/convex.config";
|
|
22
|
+
|
|
23
|
+
const app = defineApp();
|
|
24
|
+
app.use(batchProcessor);
|
|
25
|
+
|
|
26
|
+
export default app;
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
### Batch Accumulator
|
|
32
|
+
|
|
33
|
+
The batch accumulator collects items and flushes them based on:
|
|
34
|
+
- **Size threshold**: Flush when `maxBatchSize` items collected
|
|
35
|
+
- **Time interval**: Flush automatically after `flushIntervalMs` since first item was added
|
|
36
|
+
- **Manual trigger**: Force flush via API call
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { mutation, internalAction } from "./_generated/server";
|
|
40
|
+
import { internal, components } from "./_generated/api";
|
|
41
|
+
import { BatchProcessor } from "convex-batch-processor";
|
|
42
|
+
import { v } from "convex/values";
|
|
43
|
+
|
|
44
|
+
// Define the event schema
|
|
45
|
+
const analyticsEventValidator = v.object({
|
|
46
|
+
eventName: v.string(),
|
|
47
|
+
properties: v.optional(v.record(v.string(), v.string())),
|
|
48
|
+
timestamp: v.number(),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
type AnalyticsEvent = typeof analyticsEventValidator.type;
|
|
52
|
+
|
|
53
|
+
// Create a batch processor with config
|
|
54
|
+
const batchProcessor = new BatchProcessor<AnalyticsEvent>(components.batchProcessor, {
|
|
55
|
+
maxBatchSize: 100,
|
|
56
|
+
flushIntervalMs: 30000,
|
|
57
|
+
processBatch: internal.analytics.processEventsBatch,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Define the batch processor (must be an action)
|
|
61
|
+
export const processEventsBatch = internalAction({
|
|
62
|
+
args: { items: v.array(analyticsEventValidator) },
|
|
63
|
+
handler: async (ctx, { items }) => {
|
|
64
|
+
await fetch("https://api.analytics.com/batch", {
|
|
65
|
+
method: "POST",
|
|
66
|
+
body: JSON.stringify({ events: items }),
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Add items to a batch
|
|
72
|
+
export const trackEvent = mutation({
|
|
73
|
+
args: {
|
|
74
|
+
eventName: v.string(),
|
|
75
|
+
properties: v.optional(v.record(v.string(), v.string())),
|
|
76
|
+
},
|
|
77
|
+
handler: async (ctx, { eventName, properties }) => {
|
|
78
|
+
const event: AnalyticsEvent = { eventName, properties, timestamp: Date.now() };
|
|
79
|
+
|
|
80
|
+
return await batchProcessor.addItems(ctx, "analytics-events", [event]);
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Manual flush
|
|
85
|
+
await batchProcessor.flush(ctx, "analytics-events");
|
|
86
|
+
|
|
87
|
+
// Get batch status
|
|
88
|
+
await batchProcessor.getBatchStatus(ctx, "analytics-events");
|
|
89
|
+
|
|
90
|
+
// Get flush history
|
|
91
|
+
await batchProcessor.getFlushHistory(ctx, "analytics-events");
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The interval flush is scheduled automatically when the first item is added to a batch. No cron job is required.
|
|
95
|
+
|
|
96
|
+
### Table Iterator
|
|
97
|
+
|
|
98
|
+
The table iterator processes large datasets using a callback-based design:
|
|
99
|
+
|
|
100
|
+
1. **You provide**: `getNextBatch` (query) + `processBatch` (action)
|
|
101
|
+
2. **Component handles**: Scheduling, progress tracking, retries, pause/resume
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
import { mutation, query, internalQuery, internalAction, internalMutation } from "./_generated/server";
|
|
105
|
+
import { internal, components } from "./_generated/api";
|
|
106
|
+
import { BatchProcessor } from "convex-batch-processor";
|
|
107
|
+
import { v } from "convex/values";
|
|
108
|
+
|
|
109
|
+
// Define the user schema
|
|
110
|
+
const userValidator = v.object({
|
|
111
|
+
_id: v.id("users"),
|
|
112
|
+
_creationTime: v.number(),
|
|
113
|
+
name: v.string(),
|
|
114
|
+
email: v.string(),
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
type User = typeof userValidator.type;
|
|
118
|
+
|
|
119
|
+
// For iterator-only usage, config is optional
|
|
120
|
+
const batchProcessor = new BatchProcessor(components.batchProcessor);
|
|
121
|
+
|
|
122
|
+
export const startMigration = mutation({
|
|
123
|
+
args: {},
|
|
124
|
+
handler: async (ctx) => {
|
|
125
|
+
const jobId = `migration-${Date.now()}`;
|
|
126
|
+
|
|
127
|
+
await batchProcessor.startIterator<User>(ctx, jobId, {
|
|
128
|
+
batchSize: 100,
|
|
129
|
+
delayBetweenBatchesMs: 100,
|
|
130
|
+
getNextBatch: internal.migrations.getNextBatch,
|
|
131
|
+
processBatch: internal.migrations.processBatch,
|
|
132
|
+
onComplete: internal.migrations.onComplete,
|
|
133
|
+
maxRetries: 5,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
return { jobId };
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
export const getNextBatch = internalQuery({
|
|
141
|
+
args: {
|
|
142
|
+
cursor: v.optional(v.string()),
|
|
143
|
+
batchSize: v.number(),
|
|
144
|
+
},
|
|
145
|
+
handler: async (ctx, { cursor, batchSize }) => {
|
|
146
|
+
const results = await ctx.db
|
|
147
|
+
.query("users")
|
|
148
|
+
.paginate({ cursor: cursor ?? null, numItems: batchSize });
|
|
149
|
+
|
|
150
|
+
return {
|
|
151
|
+
items: results.page,
|
|
152
|
+
cursor: results.continueCursor,
|
|
153
|
+
done: results.isDone,
|
|
154
|
+
};
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
export const processBatch = internalAction({
|
|
159
|
+
args: { items: v.array(userValidator) },
|
|
160
|
+
handler: async (ctx, { items }) => {
|
|
161
|
+
for (const user of items) {
|
|
162
|
+
await migrateUser(user);
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
export const onComplete = internalMutation({
|
|
168
|
+
args: {
|
|
169
|
+
jobId: v.string(),
|
|
170
|
+
processedCount: v.number(),
|
|
171
|
+
},
|
|
172
|
+
handler: async (ctx, { jobId, processedCount }) => {
|
|
173
|
+
console.log(`Migration ${jobId} completed: ${processedCount} users`);
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
#### Job Control
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
export const pause = mutation({
|
|
182
|
+
args: { jobId: v.string() },
|
|
183
|
+
handler: async (ctx, { jobId }) => {
|
|
184
|
+
return await batchProcessor.pauseIterator(ctx, jobId);
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
export const resume = mutation({
|
|
189
|
+
args: { jobId: v.string() },
|
|
190
|
+
handler: async (ctx, { jobId }) => {
|
|
191
|
+
return await batchProcessor.resumeIterator(ctx, jobId);
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
export const cancel = mutation({
|
|
196
|
+
args: { jobId: v.string() },
|
|
197
|
+
handler: async (ctx, { jobId }) => {
|
|
198
|
+
return await batchProcessor.cancelIterator(ctx, jobId);
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
export const getStatus = query({
|
|
203
|
+
args: { jobId: v.string() },
|
|
204
|
+
handler: async (ctx, { jobId }) => {
|
|
205
|
+
return await batchProcessor.getIteratorStatus(ctx, jobId);
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
export const listJobs = query({
|
|
210
|
+
args: { status: v.optional(v.string()) },
|
|
211
|
+
handler: async (ctx, { status }) => {
|
|
212
|
+
return await batchProcessor.listIteratorJobs(ctx, { status });
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## API Reference
|
|
218
|
+
|
|
219
|
+
### BatchProcessor Class
|
|
220
|
+
|
|
221
|
+
#### Batch Accumulator Methods
|
|
222
|
+
|
|
223
|
+
| Method | Description |
|
|
224
|
+
|--------|-------------|
|
|
225
|
+
| `addItems(ctx, batchId, items)` | Add items to a batch |
|
|
226
|
+
| `flush(ctx, batchId)` | Force flush a batch |
|
|
227
|
+
| `getBatchStatus(ctx, batchId)` | Get batch status |
|
|
228
|
+
| `getFlushHistory(ctx, batchId, limit?)` | Get flush history |
|
|
229
|
+
| `deleteBatch(ctx, batchId)` | Delete a completed batch |
|
|
230
|
+
|
|
231
|
+
#### Table Iterator Methods
|
|
232
|
+
|
|
233
|
+
| Method | Description |
|
|
234
|
+
|--------|-------------|
|
|
235
|
+
| `startIterator(ctx, jobId, config)` | Start a new iterator job |
|
|
236
|
+
| `pauseIterator(ctx, jobId)` | Pause a running job |
|
|
237
|
+
| `resumeIterator(ctx, jobId)` | Resume a paused job |
|
|
238
|
+
| `cancelIterator(ctx, jobId)` | Cancel a job |
|
|
239
|
+
| `getIteratorStatus(ctx, jobId)` | Get job status |
|
|
240
|
+
| `listIteratorJobs(ctx, options?)` | List jobs |
|
|
241
|
+
| `deleteIteratorJob(ctx, jobId)` | Delete a completed job |
|
|
242
|
+
|
|
243
|
+
### Types
|
|
244
|
+
|
|
245
|
+
#### BatchConfig
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
interface BatchConfig<T = unknown> {
|
|
249
|
+
maxBatchSize: number;
|
|
250
|
+
flushIntervalMs: number;
|
|
251
|
+
processBatch: FunctionReference<"action", "internal", { items: T[] }>;
|
|
252
|
+
}
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
**`processBatch` Requirements:**
|
|
256
|
+
|
|
257
|
+
The `processBatch` **must be a Convex action** (not a mutation or plain JavaScript function). This is because:
|
|
258
|
+
- The batch processor is called via `ctx.runAction()` internally
|
|
259
|
+
- Actions can perform async operations like HTTP requests, which is the typical use case for batch processing (e.g., sending events to an external analytics service)
|
|
260
|
+
|
|
261
|
+
Pass the function reference directly:
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
const batchProcessor = new BatchProcessor(components.batchProcessor, {
|
|
265
|
+
maxBatchSize: 100,
|
|
266
|
+
flushIntervalMs: 30000,
|
|
267
|
+
processBatch: internal.myModule.processBatch,
|
|
268
|
+
});
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
If you only need to write to the database (no external calls), you can still use an action that calls a mutation internally:
|
|
272
|
+
|
|
273
|
+
```typescript
|
|
274
|
+
export const processBatch = internalAction({
|
|
275
|
+
args: { items: v.array(myItemValidator) },
|
|
276
|
+
handler: async (ctx, { items }) => {
|
|
277
|
+
await ctx.runMutation(internal.myModule.writeBatchToDb, { items });
|
|
278
|
+
},
|
|
279
|
+
});
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
#### IteratorConfig
|
|
283
|
+
|
|
284
|
+
```typescript
|
|
285
|
+
interface IteratorConfig<T = unknown> {
|
|
286
|
+
batchSize: number;
|
|
287
|
+
delayBetweenBatchesMs?: number;
|
|
288
|
+
getNextBatch: FunctionReference<"query", "internal", { cursor: string | undefined; batchSize: number }>;
|
|
289
|
+
processBatch: FunctionReference<"action", "internal", { items: T[] }>;
|
|
290
|
+
onComplete?: FunctionReference<"mutation", "internal", { jobId: string; processedCount: number }>;
|
|
291
|
+
maxRetries?: number;
|
|
292
|
+
}
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
#### Callback Types
|
|
296
|
+
|
|
297
|
+
```typescript
|
|
298
|
+
interface GetNextBatchResult<T = unknown> {
|
|
299
|
+
items: T[];
|
|
300
|
+
cursor: string | undefined;
|
|
301
|
+
done: boolean;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
interface ProcessBatchArgs<T = unknown> {
|
|
305
|
+
items: T[];
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
interface OnCompleteArgs {
|
|
309
|
+
jobId: string;
|
|
310
|
+
processedCount: number;
|
|
311
|
+
}
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
## Error Handling
|
|
315
|
+
|
|
316
|
+
### Batch Accumulator
|
|
317
|
+
- Failed flushes are recorded in `flushHistory`
|
|
318
|
+
- Items are preserved for retry (batch reverts to "accumulating" state)
|
|
319
|
+
|
|
320
|
+
### Table Iterator
|
|
321
|
+
- Automatic retry with exponential backoff (1s, 2s, 4s... up to 30s)
|
|
322
|
+
- Job marked as "failed" after `maxRetries` attempts
|
|
323
|
+
- Error messages preserved in job status
|
|
324
|
+
|
|
325
|
+
## Development
|
|
326
|
+
|
|
327
|
+
```bash
|
|
328
|
+
pnpm install
|
|
329
|
+
pnpm run build
|
|
330
|
+
pnpm test
|
|
331
|
+
pnpm run lint
|
|
332
|
+
pnpm run format
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
## License
|
|
336
|
+
|
|
337
|
+
MIT
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { type FunctionReference, type GenericMutationCtx, type GenericQueryCtx } from "convex/server";
|
|
2
|
+
export type BatchStatus = "accumulating" | "flushing" | "completed";
|
|
3
|
+
export type JobStatus = "pending" | "running" | "paused" | "completed" | "failed";
|
|
4
|
+
export interface BatchConfig<T = unknown> {
|
|
5
|
+
maxBatchSize: number;
|
|
6
|
+
flushIntervalMs: number;
|
|
7
|
+
processBatch: FunctionReference<"action", "internal", {
|
|
8
|
+
items: T[];
|
|
9
|
+
}>;
|
|
10
|
+
}
|
|
11
|
+
export interface IteratorConfig<T = unknown> {
|
|
12
|
+
batchSize: number;
|
|
13
|
+
delayBetweenBatchesMs?: number;
|
|
14
|
+
getNextBatch: FunctionReference<"query", "internal", {
|
|
15
|
+
cursor: string | undefined;
|
|
16
|
+
batchSize: number;
|
|
17
|
+
}>;
|
|
18
|
+
processBatch: FunctionReference<"action", "internal", {
|
|
19
|
+
items: T[];
|
|
20
|
+
}>;
|
|
21
|
+
onComplete?: FunctionReference<"mutation", "internal", {
|
|
22
|
+
jobId: string;
|
|
23
|
+
processedCount: number;
|
|
24
|
+
}>;
|
|
25
|
+
maxRetries?: number;
|
|
26
|
+
}
|
|
27
|
+
interface InternalBatchConfig {
|
|
28
|
+
maxBatchSize: number;
|
|
29
|
+
flushIntervalMs: number;
|
|
30
|
+
processBatchHandle: string;
|
|
31
|
+
}
|
|
32
|
+
interface InternalIteratorConfig {
|
|
33
|
+
batchSize: number;
|
|
34
|
+
delayBetweenBatchesMs?: number;
|
|
35
|
+
getNextBatchHandle: string;
|
|
36
|
+
processBatchHandle: string;
|
|
37
|
+
onCompleteHandle?: string;
|
|
38
|
+
maxRetries?: number;
|
|
39
|
+
}
|
|
40
|
+
export interface BatchResult {
|
|
41
|
+
batchId: string;
|
|
42
|
+
itemCount: number;
|
|
43
|
+
flushed: boolean;
|
|
44
|
+
status: BatchStatus;
|
|
45
|
+
}
|
|
46
|
+
export interface FlushResult {
|
|
47
|
+
batchId: string;
|
|
48
|
+
itemCount: number;
|
|
49
|
+
flushed: boolean;
|
|
50
|
+
status?: BatchStatus;
|
|
51
|
+
reason?: string;
|
|
52
|
+
}
|
|
53
|
+
export interface BatchStatusResult {
|
|
54
|
+
batchId: string;
|
|
55
|
+
itemCount: number;
|
|
56
|
+
status: BatchStatus;
|
|
57
|
+
createdAt: number;
|
|
58
|
+
lastUpdatedAt: number;
|
|
59
|
+
config: BatchConfig;
|
|
60
|
+
}
|
|
61
|
+
export interface JobResult {
|
|
62
|
+
jobId: string;
|
|
63
|
+
status: JobStatus;
|
|
64
|
+
}
|
|
65
|
+
export interface JobStatusResult {
|
|
66
|
+
jobId: string;
|
|
67
|
+
status: JobStatus;
|
|
68
|
+
processedCount: number;
|
|
69
|
+
cursor?: string;
|
|
70
|
+
retryCount: number;
|
|
71
|
+
errorMessage?: string;
|
|
72
|
+
createdAt: number;
|
|
73
|
+
lastRunAt?: number;
|
|
74
|
+
config: {
|
|
75
|
+
batchSize: number;
|
|
76
|
+
delayBetweenBatchesMs: number;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export interface JobListItem {
|
|
80
|
+
jobId: string;
|
|
81
|
+
status: JobStatus;
|
|
82
|
+
processedCount: number;
|
|
83
|
+
createdAt: number;
|
|
84
|
+
lastRunAt?: number;
|
|
85
|
+
errorMessage?: string;
|
|
86
|
+
}
|
|
87
|
+
export interface FlushHistoryItem {
|
|
88
|
+
batchId: string;
|
|
89
|
+
itemCount: number;
|
|
90
|
+
flushedAt: number;
|
|
91
|
+
durationMs: number;
|
|
92
|
+
success: boolean;
|
|
93
|
+
errorMessage?: string;
|
|
94
|
+
}
|
|
95
|
+
export interface BatchProcessorAPI {
|
|
96
|
+
lib: {
|
|
97
|
+
addItems: FunctionReference<"mutation", "internal", {
|
|
98
|
+
batchId: string;
|
|
99
|
+
items: unknown[];
|
|
100
|
+
config: InternalBatchConfig;
|
|
101
|
+
}, BatchResult>;
|
|
102
|
+
flushBatch: FunctionReference<"mutation", "internal", {
|
|
103
|
+
batchId: string;
|
|
104
|
+
}, FlushResult>;
|
|
105
|
+
getBatchStatus: FunctionReference<"query", "internal", {
|
|
106
|
+
batchId: string;
|
|
107
|
+
}, BatchStatusResult | null>;
|
|
108
|
+
getFlushHistory: FunctionReference<"query", "internal", {
|
|
109
|
+
batchId: string;
|
|
110
|
+
limit?: number;
|
|
111
|
+
}, FlushHistoryItem[]>;
|
|
112
|
+
deleteBatch: FunctionReference<"mutation", "internal", {
|
|
113
|
+
batchId: string;
|
|
114
|
+
}, {
|
|
115
|
+
deleted: boolean;
|
|
116
|
+
reason?: string;
|
|
117
|
+
}>;
|
|
118
|
+
startIteratorJob: FunctionReference<"mutation", "internal", {
|
|
119
|
+
jobId: string;
|
|
120
|
+
config: InternalIteratorConfig;
|
|
121
|
+
}, JobResult>;
|
|
122
|
+
pauseIteratorJob: FunctionReference<"mutation", "internal", {
|
|
123
|
+
jobId: string;
|
|
124
|
+
}, JobResult>;
|
|
125
|
+
resumeIteratorJob: FunctionReference<"mutation", "internal", {
|
|
126
|
+
jobId: string;
|
|
127
|
+
}, JobResult>;
|
|
128
|
+
cancelIteratorJob: FunctionReference<"mutation", "internal", {
|
|
129
|
+
jobId: string;
|
|
130
|
+
}, JobResult & {
|
|
131
|
+
reason?: string;
|
|
132
|
+
}>;
|
|
133
|
+
getIteratorJobStatus: FunctionReference<"query", "internal", {
|
|
134
|
+
jobId: string;
|
|
135
|
+
}, JobStatusResult | null>;
|
|
136
|
+
listIteratorJobs: FunctionReference<"query", "internal", {
|
|
137
|
+
status?: JobStatus;
|
|
138
|
+
limit?: number;
|
|
139
|
+
}, JobListItem[]>;
|
|
140
|
+
deleteIteratorJob: FunctionReference<"mutation", "internal", {
|
|
141
|
+
jobId: string;
|
|
142
|
+
}, {
|
|
143
|
+
deleted: boolean;
|
|
144
|
+
reason?: string;
|
|
145
|
+
}>;
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
export declare class BatchProcessor<T = unknown> {
|
|
149
|
+
private component;
|
|
150
|
+
private config?;
|
|
151
|
+
private processBatchHandle;
|
|
152
|
+
constructor(component: BatchProcessorAPI, config?: BatchConfig<T>);
|
|
153
|
+
addItems(ctx: GenericMutationCtx<any>, batchId: string, items: T[]): Promise<BatchResult>;
|
|
154
|
+
flush(ctx: GenericMutationCtx<any>, batchId: string): Promise<FlushResult>;
|
|
155
|
+
getBatchStatus(ctx: GenericQueryCtx<any>, batchId: string): Promise<BatchStatusResult | null>;
|
|
156
|
+
getFlushHistory(ctx: GenericQueryCtx<any>, batchId: string, limit?: number): Promise<FlushHistoryItem[]>;
|
|
157
|
+
deleteBatch(ctx: GenericMutationCtx<any>, batchId: string): Promise<{
|
|
158
|
+
deleted: boolean;
|
|
159
|
+
reason?: string;
|
|
160
|
+
}>;
|
|
161
|
+
startIterator<T>(ctx: GenericMutationCtx<any>, jobId: string, config: IteratorConfig<T>): Promise<JobResult>;
|
|
162
|
+
pauseIterator(ctx: GenericMutationCtx<any>, jobId: string): Promise<JobResult>;
|
|
163
|
+
resumeIterator(ctx: GenericMutationCtx<any>, jobId: string): Promise<JobResult>;
|
|
164
|
+
cancelIterator(ctx: GenericMutationCtx<any>, jobId: string): Promise<JobResult & {
|
|
165
|
+
reason?: string;
|
|
166
|
+
}>;
|
|
167
|
+
getIteratorStatus(ctx: GenericQueryCtx<any>, jobId: string): Promise<JobStatusResult | null>;
|
|
168
|
+
listIteratorJobs(ctx: GenericQueryCtx<any>, options?: {
|
|
169
|
+
status?: JobStatus;
|
|
170
|
+
limit?: number;
|
|
171
|
+
}): Promise<JobListItem[]>;
|
|
172
|
+
deleteIteratorJob(ctx: GenericMutationCtx<any>, jobId: string): Promise<{
|
|
173
|
+
deleted: boolean;
|
|
174
|
+
reason?: string;
|
|
175
|
+
}>;
|
|
176
|
+
}
|
|
177
|
+
export interface GetNextBatchResult<T = unknown> {
|
|
178
|
+
items: T[];
|
|
179
|
+
cursor: string | undefined;
|
|
180
|
+
done: boolean;
|
|
181
|
+
}
|
|
182
|
+
export interface GetNextBatchArgs {
|
|
183
|
+
cursor: string | undefined;
|
|
184
|
+
batchSize: number;
|
|
185
|
+
}
|
|
186
|
+
export interface ProcessBatchArgs<T = unknown> {
|
|
187
|
+
items: T[];
|
|
188
|
+
}
|
|
189
|
+
export interface OnCompleteArgs {
|
|
190
|
+
jobId: string;
|
|
191
|
+
processedCount: number;
|
|
192
|
+
}
|
|
193
|
+
export {};
|
|
194
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EAEpB,MAAM,eAAe,CAAC;AAEvB,MAAM,MAAM,WAAW,GAAG,cAAc,GAAG,UAAU,GAAG,WAAW,CAAC;AACpE,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,WAAW,GAA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,CAAC,EAAE,SAAS,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAC9C,OAAO,CAAC,WAAW,EAAE,CAAC;IAInB,iBAAiB,CACtB,GAAG,EAAE,kBAAkB,CAAC,GAAG,CAAC,EAC5B,KAAK,EAAE,MAAM,GACX,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAGjD;AAED,MAAM,WAAW,kBAAkB,CAAC,CAAC,GAAG,OAAO;IAC9C,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,IAAI,EAAE,OAAO,CAAC;CACd;AAED,MAAM,WAAW,gBAAgB;IAChC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,OAAO;IAC5C,KAAK,EAAE,CAAC,EAAE,CAAC;CACX;AAED,MAAM,WAAW,cAAc;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { createFunctionHandle, } from "convex/server";
|
|
2
|
+
export class BatchProcessor {
|
|
3
|
+
component;
|
|
4
|
+
config;
|
|
5
|
+
processBatchHandle = null;
|
|
6
|
+
constructor(component, config) {
|
|
7
|
+
this.component = component;
|
|
8
|
+
this.config = config;
|
|
9
|
+
}
|
|
10
|
+
async addItems(ctx, batchId, items) {
|
|
11
|
+
if (!this.config) {
|
|
12
|
+
throw new Error("BatchProcessor config with processBatch is required to use addItems. Pass config to the constructor.");
|
|
13
|
+
}
|
|
14
|
+
if (!this.processBatchHandle) {
|
|
15
|
+
this.processBatchHandle = await createFunctionHandle(this.config.processBatch);
|
|
16
|
+
}
|
|
17
|
+
const internalConfig = {
|
|
18
|
+
maxBatchSize: this.config.maxBatchSize,
|
|
19
|
+
flushIntervalMs: this.config.flushIntervalMs,
|
|
20
|
+
processBatchHandle: this.processBatchHandle,
|
|
21
|
+
};
|
|
22
|
+
return await ctx.runMutation(this.component.lib.addItems, {
|
|
23
|
+
batchId,
|
|
24
|
+
items,
|
|
25
|
+
config: internalConfig,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
async flush(ctx, batchId) {
|
|
29
|
+
return await ctx.runMutation(this.component.lib.flushBatch, { batchId });
|
|
30
|
+
}
|
|
31
|
+
async getBatchStatus(ctx, batchId) {
|
|
32
|
+
return await ctx.runQuery(this.component.lib.getBatchStatus, { batchId });
|
|
33
|
+
}
|
|
34
|
+
async getFlushHistory(ctx, batchId, limit) {
|
|
35
|
+
return await ctx.runQuery(this.component.lib.getFlushHistory, { batchId, limit });
|
|
36
|
+
}
|
|
37
|
+
async deleteBatch(ctx, batchId) {
|
|
38
|
+
return await ctx.runMutation(this.component.lib.deleteBatch, { batchId });
|
|
39
|
+
}
|
|
40
|
+
async startIterator(ctx, jobId, config) {
|
|
41
|
+
const internalConfig = {
|
|
42
|
+
batchSize: config.batchSize,
|
|
43
|
+
delayBetweenBatchesMs: config.delayBetweenBatchesMs,
|
|
44
|
+
getNextBatchHandle: await createFunctionHandle(config.getNextBatch),
|
|
45
|
+
processBatchHandle: await createFunctionHandle(config.processBatch),
|
|
46
|
+
onCompleteHandle: config.onComplete
|
|
47
|
+
? await createFunctionHandle(config.onComplete)
|
|
48
|
+
: undefined,
|
|
49
|
+
maxRetries: config.maxRetries,
|
|
50
|
+
};
|
|
51
|
+
return await ctx.runMutation(this.component.lib.startIteratorJob, {
|
|
52
|
+
jobId,
|
|
53
|
+
config: internalConfig,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
async pauseIterator(ctx, jobId) {
|
|
57
|
+
return await ctx.runMutation(this.component.lib.pauseIteratorJob, { jobId });
|
|
58
|
+
}
|
|
59
|
+
async resumeIterator(ctx, jobId) {
|
|
60
|
+
return await ctx.runMutation(this.component.lib.resumeIteratorJob, { jobId });
|
|
61
|
+
}
|
|
62
|
+
async cancelIterator(ctx, jobId) {
|
|
63
|
+
return await ctx.runMutation(this.component.lib.cancelIteratorJob, { jobId });
|
|
64
|
+
}
|
|
65
|
+
async getIteratorStatus(ctx, jobId) {
|
|
66
|
+
return await ctx.runQuery(this.component.lib.getIteratorJobStatus, { jobId });
|
|
67
|
+
}
|
|
68
|
+
async listIteratorJobs(ctx, options) {
|
|
69
|
+
return await ctx.runQuery(this.component.lib.listIteratorJobs, options ?? {});
|
|
70
|
+
}
|
|
71
|
+
async deleteIteratorJob(ctx, jobId) {
|
|
72
|
+
return await ctx.runMutation(this.component.lib.deleteIteratorJob, { jobId });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,oBAAoB,GACpB,MAAM,eAAe,CAAC;AAqKvB,MAAM,OAAO,cAAc;IAClB,SAAS,CAAoB;IAC7B,MAAM,CAAkB;IACxB,kBAAkB,GAAkB,IAAI,CAAC;IAEjD,YAAY,SAA4B,EAAE,MAAuB;QAChE,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,GAA4B,EAAE,OAAe,EAAE,KAAU;QACvE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CACd,sGAAsG,CACtG,CAAC;QACH,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC9B,IAAI,CAAC,kBAAkB,GAAG,MAAM,oBAAoB,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QAChF,CAAC;QAED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AAC;IAED,KAAK,CAAC,gBAAgB,CACrB,GAAyB,EACzB,OAAgD;QAEhD,OAAO,MAAM,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,gBAAgB,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC;IAC/E,CAAC;IAED,KAAK,CAAC,iBAAiB,CACtB,GAA4B,EAC5B,KAAa;QAEb,OAAO,MAAM,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,iBAAiB,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAC/E,CAAC;CACD"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated `api` utility.
|
|
3
|
+
*
|
|
4
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
5
|
+
*
|
|
6
|
+
* To regenerate, run `npx convex dev`.
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type * as lib from "../lib.js";
|
|
10
|
+
import type { ApiFromModules, FilterApi, FunctionReference } from "convex/server";
|
|
11
|
+
declare const fullApi: ApiFromModules<{
|
|
12
|
+
lib: typeof lib;
|
|
13
|
+
}>;
|
|
14
|
+
/**
|
|
15
|
+
* A utility for referencing Convex functions in your app's public API.
|
|
16
|
+
*
|
|
17
|
+
* Usage:
|
|
18
|
+
* ```js
|
|
19
|
+
* const myFunctionReference = api.myModule.myFunction;
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare const api: FilterApi<typeof fullApi, FunctionReference<any, "public">>;
|
|
23
|
+
/**
|
|
24
|
+
* A utility for referencing Convex functions in your app's internal API.
|
|
25
|
+
*
|
|
26
|
+
* Usage:
|
|
27
|
+
* ```js
|
|
28
|
+
* const myFunctionReference = internal.myModule.myFunction;
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare const internal: FilterApi<typeof fullApi, FunctionReference<any, "internal">>;
|
|
32
|
+
export declare const components: {};
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/component/_generated/api.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,OAAO,KAAK,KAAK,GAAG,MAAM,WAAW,CAAC;AAEtC,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,iBAAiB,EAClB,MAAM,eAAe,CAAC;AAGvB,QAAA,MAAM,OAAO,EAAE,cAAc,CAAC;IAC5B,GAAG,EAAE,OAAO,GAAG,CAAC;CACjB,CAAiB,CAAC;AAEnB;;;;;;;GAOG;AACH,eAAO,MAAM,GAAG,EAAE,SAAS,CACzB,OAAO,OAAO,EACd,iBAAiB,CAAC,GAAG,EAAE,QAAQ,CAAC,CACjB,CAAC;AAElB;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,EAAE,SAAS,CAC9B,OAAO,OAAO,EACd,iBAAiB,CAAC,GAAG,EAAE,UAAU,CAAC,CACnB,CAAC;AAElB,eAAO,MAAM,UAAU,EAAqC,EAAE,CAAC"}
|