@monque/core 1.4.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CHANGELOG.md +19 -0
- package/dist/index.cjs +372 -213
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +99 -22
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +99 -22
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +372 -214
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/events/types.ts +2 -2
- package/src/index.ts +1 -0
- package/src/jobs/document-to-persisted-job.ts +16 -16
- package/src/scheduler/monque.ts +101 -96
- package/src/scheduler/services/index.ts +1 -0
- package/src/scheduler/services/job-manager.ts +100 -116
- package/src/scheduler/services/job-query.ts +81 -36
- package/src/scheduler/services/job-scheduler.ts +42 -2
- package/src/scheduler/services/lifecycle-manager.ts +154 -0
- package/src/scheduler/services/types.ts +5 -1
- package/src/scheduler/types.ts +23 -0
- package/src/shared/errors.ts +31 -0
- package/src/shared/index.ts +1 -0
|
@@ -19,11 +19,15 @@ export interface ResolvedMonqueOptions
|
|
|
19
19
|
| 'maxBackoffDelay'
|
|
20
20
|
| 'jobRetention'
|
|
21
21
|
| 'instanceConcurrency'
|
|
22
|
+
| 'maxPayloadSize'
|
|
22
23
|
| 'defaultConcurrency'
|
|
23
24
|
| 'maxConcurrency'
|
|
24
25
|
>
|
|
25
26
|
>,
|
|
26
|
-
Pick<
|
|
27
|
+
Pick<
|
|
28
|
+
MonqueOptions,
|
|
29
|
+
'maxBackoffDelay' | 'jobRetention' | 'instanceConcurrency' | 'maxPayloadSize'
|
|
30
|
+
> {
|
|
27
31
|
// Ensure resolved options use the new naming convention
|
|
28
32
|
workerConcurrency: number;
|
|
29
33
|
}
|
package/src/scheduler/types.ts
CHANGED
|
@@ -173,4 +173,27 @@ export interface MonqueOptions {
|
|
|
173
173
|
* @default false
|
|
174
174
|
*/
|
|
175
175
|
skipIndexCreation?: boolean;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Maximum allowed BSON byte size for job data payloads.
|
|
179
|
+
*
|
|
180
|
+
* When set, `enqueue()`, `now()`, and `schedule()` validate the payload size
|
|
181
|
+
* using `BSON.calculateObjectSize()` before insertion. Jobs exceeding this limit
|
|
182
|
+
* throw `PayloadTooLargeError`.
|
|
183
|
+
*
|
|
184
|
+
* When undefined, no size validation occurs.
|
|
185
|
+
*/
|
|
186
|
+
maxPayloadSize?: number | undefined;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* TTL in milliseconds for getQueueStats() result caching.
|
|
190
|
+
*
|
|
191
|
+
* When set to a positive value, repeated getQueueStats() calls with the same
|
|
192
|
+
* filter return cached results instead of re-executing the aggregation pipeline.
|
|
193
|
+
* Each unique filter (job name) maintains its own cache entry.
|
|
194
|
+
*
|
|
195
|
+
* Set to 0 to disable caching entirely.
|
|
196
|
+
* @default 5000
|
|
197
|
+
*/
|
|
198
|
+
statsCacheTtlMs?: number;
|
|
176
199
|
}
|
package/src/shared/errors.ts
CHANGED
|
@@ -223,3 +223,34 @@ export class AggregationTimeoutError extends MonqueError {
|
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Error thrown when a job payload exceeds the configured maximum BSON byte size.
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```typescript
|
|
232
|
+
* const monque = new Monque(db, { maxPayloadSize: 1_000_000 }); // 1 MB
|
|
233
|
+
*
|
|
234
|
+
* try {
|
|
235
|
+
* await monque.enqueue('job', hugePayload);
|
|
236
|
+
* } catch (error) {
|
|
237
|
+
* if (error instanceof PayloadTooLargeError) {
|
|
238
|
+
* console.error(`Payload ${error.actualSize} bytes exceeds limit ${error.maxSize} bytes`);
|
|
239
|
+
* }
|
|
240
|
+
* }
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
export class PayloadTooLargeError extends MonqueError {
|
|
244
|
+
constructor(
|
|
245
|
+
message: string,
|
|
246
|
+
public readonly actualSize: number,
|
|
247
|
+
public readonly maxSize: number,
|
|
248
|
+
) {
|
|
249
|
+
super(message);
|
|
250
|
+
this.name = 'PayloadTooLargeError';
|
|
251
|
+
/* istanbul ignore next -- @preserve captureStackTrace is always available in Node.js */
|
|
252
|
+
if (Error.captureStackTrace) {
|
|
253
|
+
Error.captureStackTrace(this, PayloadTooLargeError);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|