@nicnocquee/dataqueue 1.24.0 → 1.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -0
- package/migrations/1751131910825_add_timeout_seconds_to_job_queue.sql +2 -2
- package/migrations/1751186053000_add_job_events_table.sql +12 -8
- package/migrations/1751984773000_add_tags_to_job_queue.sql +1 -1
- package/migrations/1765809419000_add_force_kill_on_timeout_to_job_queue.sql +1 -1
- package/migrations/1771100000000_add_idempotency_key_to_job_queue.sql +7 -0
- package/migrations/1781200000000_add_wait_support.sql +12 -0
- package/migrations/1781200000001_create_waitpoints_table.sql +18 -0
- package/migrations/1781200000002_add_performance_indexes.sql +34 -0
- package/migrations/1781200000003_add_progress_to_job_queue.sql +7 -0
- package/package.json +20 -6
- package/src/backend.ts +163 -0
- package/src/backends/postgres.ts +1111 -0
- package/src/backends/redis-scripts.ts +533 -0
- package/src/backends/redis.test.ts +543 -0
- package/src/backends/redis.ts +834 -0
- package/src/db-util.ts +4 -2
- package/src/index.test.ts +6 -1
- package/src/index.ts +99 -36
- package/src/processor.test.ts +559 -18
- package/src/processor.ts +512 -44
- package/src/queue.test.ts +217 -6
- package/src/queue.ts +311 -902
- package/src/test-util.ts +32 -0
- package/src/types.ts +349 -16
- package/src/wait.test.ts +698 -0
- package/dist/cli.cjs +0 -88
- package/dist/cli.cjs.map +0 -1
- package/dist/cli.d.cts +0 -12
- package/dist/cli.d.ts +0 -12
- package/dist/cli.js +0 -81
- package/dist/cli.js.map +0 -1
- package/dist/index.cjs +0 -1420
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -445
- package/dist/index.d.ts +0 -445
- package/dist/index.js +0 -1410
- package/dist/index.js.map +0 -1
package/dist/index.d.cts
DELETED
|
@@ -1,445 +0,0 @@
|
|
|
1
|
-
import { Pool } from 'pg';
|
|
2
|
-
|
|
3
|
-
type JobType<PayloadMap> = keyof PayloadMap & string;
|
|
4
|
-
interface JobOptions<PayloadMap, T extends JobType<PayloadMap>> {
|
|
5
|
-
jobType: T;
|
|
6
|
-
payload: PayloadMap[T];
|
|
7
|
-
maxAttempts?: number;
|
|
8
|
-
priority?: number;
|
|
9
|
-
runAt?: Date | null;
|
|
10
|
-
/**
|
|
11
|
-
* Timeout for this job in milliseconds. If not set, uses the processor default or unlimited.
|
|
12
|
-
*/
|
|
13
|
-
timeoutMs?: number;
|
|
14
|
-
/**
|
|
15
|
-
* If true, the job will be forcefully terminated (using Worker Threads) when timeout is reached.
|
|
16
|
-
* If false (default), the job will only receive an AbortSignal and must handle the abort gracefully.
|
|
17
|
-
*
|
|
18
|
-
* **⚠️ RUNTIME REQUIREMENTS**: This option requires **Node.js** and uses the `worker_threads` module.
|
|
19
|
-
* It will **not work** in Bun or other runtimes that don't support Node.js worker threads.
|
|
20
|
-
*
|
|
21
|
-
* **IMPORTANT**: When `forceKillOnTimeout` is true, the handler must be serializable. This means:
|
|
22
|
-
* - The handler should be a standalone function (not a closure over external variables)
|
|
23
|
-
* - It should not capture variables from outer scopes that reference external dependencies
|
|
24
|
-
* - It should not use 'this' context unless it's a bound method
|
|
25
|
-
* - All dependencies must be importable in the worker thread context
|
|
26
|
-
*
|
|
27
|
-
* **Examples of serializable handlers:**
|
|
28
|
-
* ```ts
|
|
29
|
-
* // ✅ Good - standalone function
|
|
30
|
-
* const handler = async (payload, signal) => {
|
|
31
|
-
* await doSomething(payload);
|
|
32
|
-
* };
|
|
33
|
-
*
|
|
34
|
-
* // ✅ Good - function that imports dependencies
|
|
35
|
-
* const handler = async (payload, signal) => {
|
|
36
|
-
* const { api } = await import('./api');
|
|
37
|
-
* await api.call(payload);
|
|
38
|
-
* };
|
|
39
|
-
*
|
|
40
|
-
* // ❌ Bad - closure over external variable
|
|
41
|
-
* const db = getDatabase();
|
|
42
|
-
* const handler = async (payload, signal) => {
|
|
43
|
-
* await db.query(payload); // 'db' is captured from closure
|
|
44
|
-
* };
|
|
45
|
-
*
|
|
46
|
-
* // ❌ Bad - uses 'this' context
|
|
47
|
-
* class MyHandler {
|
|
48
|
-
* async handle(payload, signal) {
|
|
49
|
-
* await this.doSomething(payload); // 'this' won't work
|
|
50
|
-
* }
|
|
51
|
-
* }
|
|
52
|
-
* ```
|
|
53
|
-
*
|
|
54
|
-
* If your handler doesn't meet these requirements, use `forceKillOnTimeout: false` (default)
|
|
55
|
-
* and ensure your handler checks `signal.aborted` to exit gracefully.
|
|
56
|
-
*
|
|
57
|
-
* Note: forceKillOnTimeout requires timeoutMs to be set.
|
|
58
|
-
*/
|
|
59
|
-
forceKillOnTimeout?: boolean;
|
|
60
|
-
/**
|
|
61
|
-
* Tags for this job. Used for grouping, searching, or batch operations.
|
|
62
|
-
*/
|
|
63
|
-
tags?: string[];
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Options for editing a pending job.
|
|
67
|
-
* All fields are optional and only provided fields will be updated.
|
|
68
|
-
* Note: jobType cannot be changed.
|
|
69
|
-
* timeoutMs and tags can be set to null to clear them.
|
|
70
|
-
*/
|
|
71
|
-
type EditJobOptions<PayloadMap, T extends JobType<PayloadMap>> = Partial<Omit<JobOptions<PayloadMap, T>, 'jobType'>> & {
|
|
72
|
-
timeoutMs?: number | null;
|
|
73
|
-
tags?: string[] | null;
|
|
74
|
-
};
|
|
75
|
-
declare enum JobEventType {
|
|
76
|
-
Added = "added",
|
|
77
|
-
Processing = "processing",
|
|
78
|
-
Completed = "completed",
|
|
79
|
-
Failed = "failed",
|
|
80
|
-
Cancelled = "cancelled",
|
|
81
|
-
Retried = "retried",
|
|
82
|
-
Edited = "edited"
|
|
83
|
-
}
|
|
84
|
-
interface JobEvent {
|
|
85
|
-
id: number;
|
|
86
|
-
jobId: number;
|
|
87
|
-
eventType: JobEventType;
|
|
88
|
-
createdAt: Date;
|
|
89
|
-
metadata: any;
|
|
90
|
-
}
|
|
91
|
-
declare enum FailureReason {
|
|
92
|
-
Timeout = "timeout",
|
|
93
|
-
HandlerError = "handler_error",
|
|
94
|
-
NoHandler = "no_handler"
|
|
95
|
-
}
|
|
96
|
-
type JobStatus = 'pending' | 'processing' | 'completed' | 'failed' | 'cancelled';
|
|
97
|
-
interface JobRecord<PayloadMap, T extends JobType<PayloadMap>> {
|
|
98
|
-
id: number;
|
|
99
|
-
jobType: T;
|
|
100
|
-
payload: PayloadMap[T];
|
|
101
|
-
status: JobStatus;
|
|
102
|
-
createdAt: Date;
|
|
103
|
-
updatedAt: Date;
|
|
104
|
-
lockedAt: Date | null;
|
|
105
|
-
lockedBy: string | null;
|
|
106
|
-
attempts: number;
|
|
107
|
-
maxAttempts: number;
|
|
108
|
-
nextAttemptAt: Date | null;
|
|
109
|
-
priority: number;
|
|
110
|
-
runAt: Date;
|
|
111
|
-
pendingReason?: string | null;
|
|
112
|
-
errorHistory?: {
|
|
113
|
-
message: string;
|
|
114
|
-
timestamp: string;
|
|
115
|
-
}[];
|
|
116
|
-
/**
|
|
117
|
-
* Timeout for this job in milliseconds (null means no timeout).
|
|
118
|
-
*/
|
|
119
|
-
timeoutMs?: number | null;
|
|
120
|
-
/**
|
|
121
|
-
* If true, the job will be forcefully terminated (using Worker Threads) when timeout is reached.
|
|
122
|
-
* If false (default), the job will only receive an AbortSignal and must handle the abort gracefully.
|
|
123
|
-
*/
|
|
124
|
-
forceKillOnTimeout?: boolean | null;
|
|
125
|
-
/**
|
|
126
|
-
* The reason for the last failure, if any.
|
|
127
|
-
*/
|
|
128
|
-
failureReason?: FailureReason | null;
|
|
129
|
-
/**
|
|
130
|
-
* The time the job was completed, if completed.
|
|
131
|
-
*/
|
|
132
|
-
completedAt: Date | null;
|
|
133
|
-
/**
|
|
134
|
-
* The time the job was first picked up for processing.
|
|
135
|
-
*/
|
|
136
|
-
startedAt: Date | null;
|
|
137
|
-
/**
|
|
138
|
-
* The time the job was last retried.
|
|
139
|
-
*/
|
|
140
|
-
lastRetriedAt: Date | null;
|
|
141
|
-
/**
|
|
142
|
-
* The time the job last failed.
|
|
143
|
-
*/
|
|
144
|
-
lastFailedAt: Date | null;
|
|
145
|
-
/**
|
|
146
|
-
* The time the job was last cancelled.
|
|
147
|
-
*/
|
|
148
|
-
lastCancelledAt: Date | null;
|
|
149
|
-
/**
|
|
150
|
-
* Tags for this job. Used for grouping, searching, or batch operations.
|
|
151
|
-
*/
|
|
152
|
-
tags?: string[];
|
|
153
|
-
}
|
|
154
|
-
type JobHandler<PayloadMap, T extends keyof PayloadMap> = (payload: PayloadMap[T], signal: AbortSignal) => Promise<void>;
|
|
155
|
-
type JobHandlers<PayloadMap> = {
|
|
156
|
-
[K in keyof PayloadMap]: JobHandler<PayloadMap, K>;
|
|
157
|
-
};
|
|
158
|
-
interface ProcessorOptions {
|
|
159
|
-
workerId?: string;
|
|
160
|
-
/**
|
|
161
|
-
* The number of jobs to process at a time.
|
|
162
|
-
* - If not provided, the processor will process 10 jobs at a time.
|
|
163
|
-
* - In serverless functions, it's better to process less jobs at a time since serverless functions are charged by the second and have a timeout.
|
|
164
|
-
*/
|
|
165
|
-
batchSize?: number;
|
|
166
|
-
/**
|
|
167
|
-
* The maximum number of jobs to process in parallel per batch.
|
|
168
|
-
* - If not provided, all jobs in the batch are processed in parallel.
|
|
169
|
-
* - Set to 1 to process jobs sequentially.
|
|
170
|
-
* - Set to a lower value to avoid resource exhaustion.
|
|
171
|
-
*/
|
|
172
|
-
concurrency?: number;
|
|
173
|
-
/**
|
|
174
|
-
* The interval in milliseconds to poll for new jobs.
|
|
175
|
-
* - If not provided, the processor will process jobs every 5 seconds when startInBackground is called.
|
|
176
|
-
* - In serverless functions, it's better to leave this empty.
|
|
177
|
-
* - If you call start instead of startInBackground, the pollInterval is ignored.
|
|
178
|
-
*/
|
|
179
|
-
pollInterval?: number;
|
|
180
|
-
onError?: (error: Error) => void;
|
|
181
|
-
verbose?: boolean;
|
|
182
|
-
/**
|
|
183
|
-
* Only process jobs with this job type (string or array of strings). If omitted, all job types are processed.
|
|
184
|
-
*/
|
|
185
|
-
jobType?: string | string[];
|
|
186
|
-
}
|
|
187
|
-
interface Processor {
|
|
188
|
-
/**
|
|
189
|
-
* Start the job processor in the background.
|
|
190
|
-
* - This will run periodically (every pollInterval milliseconds or 5 seconds if not provided) and process jobs (as many as batchSize) as they become available.
|
|
191
|
-
* - **You have to call the stop method to stop the processor.**
|
|
192
|
-
* - Handlers are provided per-processor when calling createProcessor.
|
|
193
|
-
* - In serverless functions, it's recommended to call start instead and await it to finish.
|
|
194
|
-
*/
|
|
195
|
-
startInBackground: () => void;
|
|
196
|
-
/**
|
|
197
|
-
* Stop the job processor that runs in the background.
|
|
198
|
-
*/
|
|
199
|
-
stop: () => void;
|
|
200
|
-
/**
|
|
201
|
-
* Check if the job processor is running.
|
|
202
|
-
*/
|
|
203
|
-
isRunning: () => boolean;
|
|
204
|
-
/**
|
|
205
|
-
* Start the job processor synchronously.
|
|
206
|
-
* - This will process jobs (as many as batchSize) immediately and then stop. The pollInterval is ignored.
|
|
207
|
-
* - In serverless functions, it's recommended to use this instead of startInBackground.
|
|
208
|
-
* - Returns the number of jobs processed.
|
|
209
|
-
*/
|
|
210
|
-
start: () => Promise<number>;
|
|
211
|
-
}
|
|
212
|
-
interface DatabaseSSLConfig {
|
|
213
|
-
/**
|
|
214
|
-
* CA certificate as PEM string or file path. If the value starts with 'file://', it will be loaded from file, otherwise treated as PEM string.
|
|
215
|
-
*/
|
|
216
|
-
ca?: string;
|
|
217
|
-
/**
|
|
218
|
-
* Client certificate as PEM string or file path. If the value starts with 'file://', it will be loaded from file, otherwise treated as PEM string.
|
|
219
|
-
*/
|
|
220
|
-
cert?: string;
|
|
221
|
-
/**
|
|
222
|
-
* Client private key as PEM string or file path. If the value starts with 'file://', it will be loaded from file, otherwise treated as PEM string.
|
|
223
|
-
*/
|
|
224
|
-
key?: string;
|
|
225
|
-
/**
|
|
226
|
-
* Whether to reject unauthorized certificates (default: true)
|
|
227
|
-
*/
|
|
228
|
-
rejectUnauthorized?: boolean;
|
|
229
|
-
}
|
|
230
|
-
interface JobQueueConfig {
|
|
231
|
-
databaseConfig: {
|
|
232
|
-
connectionString?: string;
|
|
233
|
-
host?: string;
|
|
234
|
-
port?: number;
|
|
235
|
-
database?: string;
|
|
236
|
-
user?: string;
|
|
237
|
-
password?: string;
|
|
238
|
-
ssl?: DatabaseSSLConfig;
|
|
239
|
-
};
|
|
240
|
-
verbose?: boolean;
|
|
241
|
-
}
|
|
242
|
-
type TagQueryMode = 'exact' | 'all' | 'any' | 'none';
|
|
243
|
-
interface JobQueue<PayloadMap> {
|
|
244
|
-
/**
|
|
245
|
-
* Add a job to the job queue.
|
|
246
|
-
*/
|
|
247
|
-
addJob: <T extends JobType<PayloadMap>>(job: JobOptions<PayloadMap, T>) => Promise<number>;
|
|
248
|
-
/**
|
|
249
|
-
* Get a job by its ID.
|
|
250
|
-
*/
|
|
251
|
-
getJob: <T extends JobType<PayloadMap>>(id: number) => Promise<JobRecord<PayloadMap, T> | null>;
|
|
252
|
-
/**
|
|
253
|
-
* Get jobs by their status, with pagination.
|
|
254
|
-
* - If no limit is provided, all jobs are returned.
|
|
255
|
-
* - If no offset is provided, the first page is returned.
|
|
256
|
-
* - The jobs are returned in descending order of createdAt.
|
|
257
|
-
*/
|
|
258
|
-
getJobsByStatus: <T extends JobType<PayloadMap>>(status: JobStatus, limit?: number, offset?: number) => Promise<JobRecord<PayloadMap, T>[]>;
|
|
259
|
-
/**
|
|
260
|
-
* Get jobs by tag(s).
|
|
261
|
-
* - Modes:
|
|
262
|
-
* - 'exact': Jobs with exactly the same tags (no more, no less)
|
|
263
|
-
* - 'all': Jobs that have all the given tags (can have more)
|
|
264
|
-
* - 'any': Jobs that have at least one of the given tags
|
|
265
|
-
* - 'none': Jobs that have none of the given tags
|
|
266
|
-
* - Default mode is 'all'.
|
|
267
|
-
*/
|
|
268
|
-
getJobsByTags: <T extends JobType<PayloadMap>>(tags: string[], mode?: TagQueryMode, limit?: number, offset?: number) => Promise<JobRecord<PayloadMap, T>[]>;
|
|
269
|
-
/**
|
|
270
|
-
* Get all jobs.
|
|
271
|
-
*/
|
|
272
|
-
getAllJobs: <T extends JobType<PayloadMap>>(limit?: number, offset?: number) => Promise<JobRecord<PayloadMap, T>[]>;
|
|
273
|
-
/**
|
|
274
|
-
* Get jobs by filters.
|
|
275
|
-
/**
|
|
276
|
-
* Get jobs by filters.
|
|
277
|
-
*/
|
|
278
|
-
getJobs: <T extends JobType<PayloadMap>>(filters?: {
|
|
279
|
-
jobType?: string;
|
|
280
|
-
priority?: number;
|
|
281
|
-
runAt?: Date | {
|
|
282
|
-
gt?: Date;
|
|
283
|
-
gte?: Date;
|
|
284
|
-
lt?: Date;
|
|
285
|
-
lte?: Date;
|
|
286
|
-
eq?: Date;
|
|
287
|
-
};
|
|
288
|
-
tags?: {
|
|
289
|
-
values: string[];
|
|
290
|
-
mode?: TagQueryMode;
|
|
291
|
-
};
|
|
292
|
-
}) => Promise<JobRecord<PayloadMap, T>[]>;
|
|
293
|
-
/**
|
|
294
|
-
* Retry a job given its ID.
|
|
295
|
-
* - This will set the job status back to 'pending', clear the locked_at and locked_by, and allow it to be picked up by other workers.
|
|
296
|
-
*/
|
|
297
|
-
retryJob: (jobId: number) => Promise<void>;
|
|
298
|
-
/**
|
|
299
|
-
* Cleanup jobs that are older than the specified number of days.
|
|
300
|
-
*/
|
|
301
|
-
cleanupOldJobs: (daysToKeep?: number) => Promise<number>;
|
|
302
|
-
/**
|
|
303
|
-
* Cancel a job given its ID.
|
|
304
|
-
* - This will set the job status to 'cancelled' and clear the locked_at and locked_by.
|
|
305
|
-
*/
|
|
306
|
-
cancelJob: (jobId: number) => Promise<void>;
|
|
307
|
-
/**
|
|
308
|
-
* Edit a pending job given its ID.
|
|
309
|
-
* - Only works for jobs with status 'pending'. Silently fails for other statuses.
|
|
310
|
-
* - All fields in EditJobOptions are optional - only provided fields will be updated.
|
|
311
|
-
* - jobType cannot be changed.
|
|
312
|
-
* - Records an 'edited' event with the updated fields in metadata.
|
|
313
|
-
*/
|
|
314
|
-
editJob: <T extends JobType<PayloadMap>>(jobId: number, updates: EditJobOptions<PayloadMap, T>) => Promise<void>;
|
|
315
|
-
/**
|
|
316
|
-
* Edit all pending jobs that match the filters.
|
|
317
|
-
* - Only works for jobs with status 'pending'. Non-pending jobs are not affected.
|
|
318
|
-
* - All fields in EditJobOptions are optional - only provided fields will be updated.
|
|
319
|
-
* - jobType cannot be changed.
|
|
320
|
-
* - Records an 'edited' event with the updated fields in metadata for each affected job.
|
|
321
|
-
* - Returns the number of jobs that were edited.
|
|
322
|
-
* - The filters are:
|
|
323
|
-
* - jobType: The job type to edit.
|
|
324
|
-
* - priority: The priority of the job to edit.
|
|
325
|
-
* - runAt: The time the job is scheduled to run at (now supports gt/gte/lt/lte/eq).
|
|
326
|
-
* - tags: An object with 'values' (string[]) and 'mode' (TagQueryMode) for tag-based editing.
|
|
327
|
-
*/
|
|
328
|
-
editAllPendingJobs: <T extends JobType<PayloadMap>>(filters: {
|
|
329
|
-
jobType?: string;
|
|
330
|
-
priority?: number;
|
|
331
|
-
runAt?: Date | {
|
|
332
|
-
gt?: Date;
|
|
333
|
-
gte?: Date;
|
|
334
|
-
lt?: Date;
|
|
335
|
-
lte?: Date;
|
|
336
|
-
eq?: Date;
|
|
337
|
-
};
|
|
338
|
-
tags?: {
|
|
339
|
-
values: string[];
|
|
340
|
-
mode?: TagQueryMode;
|
|
341
|
-
};
|
|
342
|
-
} | undefined, updates: EditJobOptions<PayloadMap, T>) => Promise<number>;
|
|
343
|
-
/**
|
|
344
|
-
* Reclaim stuck jobs.
|
|
345
|
-
* - If a process (e.g., API route or worker) crashes after marking a job as 'processing' but before completing it, the job can remain stuck in the 'processing' state indefinitely. This can happen if the process is killed or encounters an unhandled error after updating the job status but before marking it as 'completed' or 'failed'.
|
|
346
|
-
* - This function will set the job status back to 'pending', clear the locked_at and locked_by, and allow it to be picked up by other workers.
|
|
347
|
-
* - The default max processing time is 10 minutes.
|
|
348
|
-
*/
|
|
349
|
-
reclaimStuckJobs: (maxProcessingTimeMinutes?: number) => Promise<number>;
|
|
350
|
-
/**
|
|
351
|
-
* Cancel all upcoming jobs that match the filters.
|
|
352
|
-
* - If no filters are provided, all upcoming jobs are cancelled.
|
|
353
|
-
* - If filters are provided, only jobs that match the filters are cancelled.
|
|
354
|
-
* - The filters are:
|
|
355
|
-
* - jobType: The job type to cancel.
|
|
356
|
-
* - priority: The priority of the job to cancel.
|
|
357
|
-
* - runAt: The time the job is scheduled to run at (now supports gt/gte/lt/lte/eq).
|
|
358
|
-
* - tags: An object with 'values' (string[]) and 'mode' (TagQueryMode) for tag-based cancellation.
|
|
359
|
-
*/
|
|
360
|
-
cancelAllUpcomingJobs: (filters?: {
|
|
361
|
-
jobType?: string;
|
|
362
|
-
priority?: number;
|
|
363
|
-
runAt?: Date | {
|
|
364
|
-
gt?: Date;
|
|
365
|
-
gte?: Date;
|
|
366
|
-
lt?: Date;
|
|
367
|
-
lte?: Date;
|
|
368
|
-
eq?: Date;
|
|
369
|
-
};
|
|
370
|
-
tags?: {
|
|
371
|
-
values: string[];
|
|
372
|
-
mode?: TagQueryMode;
|
|
373
|
-
};
|
|
374
|
-
}) => Promise<number>;
|
|
375
|
-
/**
|
|
376
|
-
* Create a job processor. Handlers must be provided per-processor.
|
|
377
|
-
*/
|
|
378
|
-
createProcessor: (handlers: JobHandlers<PayloadMap>, options?: ProcessorOptions) => Processor;
|
|
379
|
-
/**
|
|
380
|
-
* Get the job events for a job.
|
|
381
|
-
*/
|
|
382
|
-
getJobEvents: (jobId: number) => Promise<JobEvent[]>;
|
|
383
|
-
/**
|
|
384
|
-
* Get the database pool.
|
|
385
|
-
*/
|
|
386
|
-
getPool: () => Pool;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
/**
|
|
390
|
-
* Validates that a job handler can be serialized for use with forceKillOnTimeout.
|
|
391
|
-
*
|
|
392
|
-
* This function checks if a handler can be safely serialized and executed in a worker thread.
|
|
393
|
-
* Use this function during development to catch serialization issues early.
|
|
394
|
-
*
|
|
395
|
-
* @param handler - The job handler function to validate
|
|
396
|
-
* @param jobType - Optional job type name for better error messages
|
|
397
|
-
* @returns An object with `isSerializable` boolean and optional `error` message
|
|
398
|
-
*
|
|
399
|
-
* @example
|
|
400
|
-
* ```ts
|
|
401
|
-
* const handler = async (payload, signal) => {
|
|
402
|
-
* await doSomething(payload);
|
|
403
|
-
* };
|
|
404
|
-
*
|
|
405
|
-
* const result = validateHandlerSerializable(handler, 'myJob');
|
|
406
|
-
* if (!result.isSerializable) {
|
|
407
|
-
* console.error('Handler is not serializable:', result.error);
|
|
408
|
-
* }
|
|
409
|
-
* ```
|
|
410
|
-
*/
|
|
411
|
-
declare function validateHandlerSerializable<PayloadMap, T extends keyof PayloadMap & string>(handler: JobHandler<PayloadMap, T>, jobType?: string): {
|
|
412
|
-
isSerializable: boolean;
|
|
413
|
-
error?: string;
|
|
414
|
-
};
|
|
415
|
-
/**
|
|
416
|
-
* Test if a handler can be serialized and executed in a worker thread.
|
|
417
|
-
* This is a more thorough check that actually attempts to serialize and deserialize the handler.
|
|
418
|
-
*
|
|
419
|
-
* @param handler - The job handler function to test
|
|
420
|
-
* @param jobType - Optional job type name for better error messages
|
|
421
|
-
* @returns Promise that resolves to validation result
|
|
422
|
-
*
|
|
423
|
-
* @example
|
|
424
|
-
* ```ts
|
|
425
|
-
* const handler = async (payload, signal) => {
|
|
426
|
-
* await doSomething(payload);
|
|
427
|
-
* };
|
|
428
|
-
*
|
|
429
|
-
* const result = await testHandlerSerialization(handler, 'myJob');
|
|
430
|
-
* if (!result.isSerializable) {
|
|
431
|
-
* console.error('Handler failed serialization test:', result.error);
|
|
432
|
-
* }
|
|
433
|
-
* ```
|
|
434
|
-
*/
|
|
435
|
-
declare function testHandlerSerialization<PayloadMap, T extends keyof PayloadMap & string>(handler: JobHandler<PayloadMap, T>, jobType?: string): Promise<{
|
|
436
|
-
isSerializable: boolean;
|
|
437
|
-
error?: string;
|
|
438
|
-
}>;
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* Initialize the job queue system
|
|
442
|
-
*/
|
|
443
|
-
declare const initJobQueue: <PayloadMap = any>(config: JobQueueConfig) => JobQueue<PayloadMap>;
|
|
444
|
-
|
|
445
|
-
export { type DatabaseSSLConfig, type EditJobOptions, FailureReason, type JobEvent, JobEventType, type JobHandler, type JobHandlers, type JobOptions, type JobQueue, type JobQueueConfig, type JobRecord, type JobStatus, type JobType, type Processor, type ProcessorOptions, type TagQueryMode, initJobQueue, testHandlerSerialization, validateHandlerSerializable };
|