@monque/core 1.4.0 → 1.5.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/dist/index.d.cts CHANGED
@@ -578,16 +578,16 @@ interface MonqueEventMap {
578
578
  };
579
579
  /**
580
580
  * Emitted when multiple jobs are cancelled in bulk.
581
+ * Contains only the count of affected jobs (no individual IDs for O(1) performance).
581
582
  */
582
583
  'jobs:cancelled': {
583
- jobIds: string[];
584
584
  count: number;
585
585
  };
586
586
  /**
587
587
  * Emitted when multiple jobs are retried in bulk.
588
+ * Contains only the count of affected jobs (no individual IDs for O(1) performance).
588
589
  */
589
590
  'jobs:retried': {
590
- jobIds: string[];
591
591
  count: number;
592
592
  };
593
593
  /**
@@ -780,6 +780,27 @@ interface MonqueOptions {
780
780
  * @default false
781
781
  */
782
782
  skipIndexCreation?: boolean;
783
+ /**
784
+ * Maximum allowed BSON byte size for job data payloads.
785
+ *
786
+ * When set, `enqueue()`, `now()`, and `schedule()` validate the payload size
787
+ * using `BSON.calculateObjectSize()` before insertion. Jobs exceeding this limit
788
+ * throw `PayloadTooLargeError`.
789
+ *
790
+ * When undefined, no size validation occurs.
791
+ */
792
+ maxPayloadSize?: number | undefined;
793
+ /**
794
+ * TTL in milliseconds for getQueueStats() result caching.
795
+ *
796
+ * When set to a positive value, repeated getQueueStats() calls with the same
797
+ * filter return cached results instead of re-executing the aggregation pipeline.
798
+ * Each unique filter (job name) maintains its own cache entry.
799
+ *
800
+ * Set to 0 to disable caching entirely.
801
+ * @default 5000
802
+ */
803
+ statsCacheTtlMs?: number;
783
804
  }
784
805
  //#endregion
785
806
  //#region src/scheduler/monque.d.ts
@@ -852,9 +873,6 @@ declare class Monque extends EventEmitter {
852
873
  private readonly options;
853
874
  private collection;
854
875
  private workers;
855
- private pollIntervalId;
856
- private heartbeatIntervalId;
857
- private cleanupIntervalId;
858
876
  private isRunning;
859
877
  private isInitialized;
860
878
  private _scheduler;
@@ -862,6 +880,7 @@ declare class Monque extends EventEmitter {
862
880
  private _query;
863
881
  private _processor;
864
882
  private _changeStreamHandler;
883
+ private _lifecycleManager;
865
884
  constructor(db: Db, options?: MonqueOptions);
866
885
  /**
867
886
  * Initialize the scheduler by setting up the MongoDB collection and indexes.
@@ -880,6 +899,8 @@ declare class Monque extends EventEmitter {
880
899
  private get processor();
881
900
  /** @throws {ConnectionError} if not initialized */
882
901
  private get changeStreamHandler();
902
+ /** @throws {ConnectionError} if not initialized */
903
+ private get lifecycleManager();
883
904
  /**
884
905
  * Build the shared context for internal services.
885
906
  */
@@ -904,16 +925,15 @@ declare class Monque extends EventEmitter {
904
925
  */
905
926
  private recoverStaleJobs;
906
927
  /**
907
- * Clean up old completed and failed jobs based on retention policy.
908
- *
909
- * - Removes completed jobs older than `jobRetention.completed`
910
- * - Removes failed jobs older than `jobRetention.failed`
928
+ * Check if another active instance is using the same schedulerInstanceId.
929
+ * Uses heartbeat staleness to distinguish active instances from crashed ones.
911
930
  *
912
- * The cleanup runs concurrently for both statuses if configured.
931
+ * Called after stale recovery to avoid false positives: stale recovery resets
932
+ * jobs with old `lockedAt`, so only jobs with recent heartbeats remain.
913
933
  *
914
- * @returns Promise resolving when all deletion operations complete
934
+ * @throws {ConnectionError} If an active instance with the same ID is detected
915
935
  */
916
- private cleanupJobs;
936
+ private checkInstanceCollision;
917
937
  /**
918
938
  * Enqueue a job for processing.
919
939
  *
@@ -932,6 +952,7 @@ declare class Monque extends EventEmitter {
932
952
  * @param options - Scheduling and deduplication options
933
953
  * @returns Promise resolving to the created or existing job document
934
954
  * @throws {ConnectionError} If database operation fails or scheduler not initialized
955
+ * @throws {PayloadTooLargeError} If payload exceeds configured `maxPayloadSize`
935
956
  *
936
957
  * @example Basic job enqueueing
937
958
  * ```typescript
@@ -957,6 +978,8 @@ declare class Monque extends EventEmitter {
957
978
  * });
958
979
  * // Subsequent enqueues with same uniqueKey return existing pending/processing job
959
980
  * ```
981
+ *
982
+ * @see {@link JobScheduler.enqueue}
960
983
  */
961
984
  enqueue<T>(name: string, data: T, options?: EnqueueOptions): Promise<PersistedJob<T>>;
962
985
  /**
@@ -986,6 +1009,8 @@ declare class Monque extends EventEmitter {
986
1009
  * await monque.now('process-order', { orderId: order.id });
987
1010
  * return order; // Return immediately, processing happens async
988
1011
  * ```
1012
+ *
1013
+ * @see {@link JobScheduler.now}
989
1014
  */
990
1015
  now<T>(name: string, data: T): Promise<PersistedJob<T>>;
991
1016
  /**
@@ -1008,6 +1033,7 @@ declare class Monque extends EventEmitter {
1008
1033
  * @returns Promise resolving to the created job document with `repeatInterval` set
1009
1034
  * @throws {InvalidCronError} If cron expression is invalid
1010
1035
  * @throws {ConnectionError} If database operation fails or scheduler not initialized
1036
+ * @throws {PayloadTooLargeError} If payload exceeds configured `maxPayloadSize`
1011
1037
  *
1012
1038
  * @example Hourly cleanup job
1013
1039
  * ```typescript
@@ -1031,6 +1057,8 @@ declare class Monque extends EventEmitter {
1031
1057
  * recipients: ['analytics@example.com']
1032
1058
  * });
1033
1059
  * ```
1060
+ *
1061
+ * @see {@link JobScheduler.schedule}
1034
1062
  */
1035
1063
  schedule<T>(cron: string, name: string, data: T, options?: ScheduleOptions): Promise<PersistedJob<T>>;
1036
1064
  /**
@@ -1049,6 +1077,8 @@ declare class Monque extends EventEmitter {
1049
1077
  * const job = await monque.enqueue('report', { type: 'daily' });
1050
1078
  * await monque.cancelJob(job._id.toString());
1051
1079
  * ```
1080
+ *
1081
+ * @see {@link JobManager.cancelJob}
1052
1082
  */
1053
1083
  cancelJob(jobId: string): Promise<PersistedJob<unknown> | null>;
1054
1084
  /**
@@ -1068,6 +1098,8 @@ declare class Monque extends EventEmitter {
1068
1098
  * await monque.retryJob(job._id.toString());
1069
1099
  * });
1070
1100
  * ```
1101
+ *
1102
+ * @see {@link JobManager.retryJob}
1071
1103
  */
1072
1104
  retryJob(jobId: string): Promise<PersistedJob<unknown> | null>;
1073
1105
  /**
@@ -1085,6 +1117,8 @@ declare class Monque extends EventEmitter {
1085
1117
  * const nextHour = new Date(Date.now() + 60 * 60 * 1000);
1086
1118
  * await monque.rescheduleJob(jobId, nextHour);
1087
1119
  * ```
1120
+ *
1121
+ * @see {@link JobManager.rescheduleJob}
1088
1122
  */
1089
1123
  rescheduleJob(jobId: string, runAt: Date): Promise<PersistedJob<unknown> | null>;
1090
1124
  /**
@@ -1103,17 +1137,20 @@ declare class Monque extends EventEmitter {
1103
1137
  * console.log('Job permanently removed');
1104
1138
  * }
1105
1139
  * ```
1140
+ *
1141
+ * @see {@link JobManager.deleteJob}
1106
1142
  */
1107
1143
  deleteJob(jobId: string): Promise<boolean>;
1108
1144
  /**
1109
- * Cancel multiple jobs matching the given filter.
1145
+ * Cancel multiple jobs matching the given filter via a single updateMany call.
1110
1146
  *
1111
- * Only cancels jobs in 'pending' status. Jobs in other states are collected
1112
- * as errors in the result. Emits a 'jobs:cancelled' event with the IDs of
1147
+ * Only cancels jobs in 'pending' status the status guard is applied regardless
1148
+ * of what the filter specifies. Jobs in other states are silently skipped (not
1149
+ * matched by the query). Emits a 'jobs:cancelled' event with the count of
1113
1150
  * successfully cancelled jobs.
1114
1151
  *
1115
1152
  * @param filter - Selector for which jobs to cancel (name, status, date range)
1116
- * @returns Result with count of cancelled jobs and any errors encountered
1153
+ * @returns Result with count of cancelled jobs (errors array always empty for bulk ops)
1117
1154
  *
1118
1155
  * @example Cancel all pending jobs for a queue
1119
1156
  * ```typescript
@@ -1123,17 +1160,20 @@ declare class Monque extends EventEmitter {
1123
1160
  * });
1124
1161
  * console.log(`Cancelled ${result.count} jobs`);
1125
1162
  * ```
1163
+ *
1164
+ * @see {@link JobManager.cancelJobs}
1126
1165
  */
1127
1166
  cancelJobs(filter: JobSelector): Promise<BulkOperationResult>;
1128
1167
  /**
1129
- * Retry multiple jobs matching the given filter.
1168
+ * Retry multiple jobs matching the given filter via a single pipeline-style updateMany call.
1130
1169
  *
1131
- * Only retries jobs in 'failed' or 'cancelled' status. Jobs in other states
1132
- * are collected as errors in the result. Emits a 'jobs:retried' event with
1133
- * the IDs of successfully retried jobs.
1170
+ * Only retries jobs in 'failed' or 'cancelled' status the status guard is applied
1171
+ * regardless of what the filter specifies. Jobs in other states are silently skipped.
1172
+ * Uses `$rand` for per-document staggered `nextRunAt` to avoid thundering herd on retry.
1173
+ * Emits a 'jobs:retried' event with the count of successfully retried jobs.
1134
1174
  *
1135
1175
  * @param filter - Selector for which jobs to retry (name, status, date range)
1136
- * @returns Result with count of retried jobs and any errors encountered
1176
+ * @returns Result with count of retried jobs (errors array always empty for bulk ops)
1137
1177
  *
1138
1178
  * @example Retry all failed jobs
1139
1179
  * ```typescript
@@ -1142,12 +1182,15 @@ declare class Monque extends EventEmitter {
1142
1182
  * });
1143
1183
  * console.log(`Retried ${result.count} jobs`);
1144
1184
  * ```
1185
+ *
1186
+ * @see {@link JobManager.retryJobs}
1145
1187
  */
1146
1188
  retryJobs(filter: JobSelector): Promise<BulkOperationResult>;
1147
1189
  /**
1148
1190
  * Delete multiple jobs matching the given filter.
1149
1191
  *
1150
1192
  * Deletes jobs in any status. Uses a batch delete for efficiency.
1193
+ * Emits a 'jobs:deleted' event with the count of deleted jobs.
1151
1194
  * Does not emit individual 'job:deleted' events to avoid noise.
1152
1195
  *
1153
1196
  * @param filter - Selector for which jobs to delete (name, status, date range)
@@ -1162,6 +1205,8 @@ declare class Monque extends EventEmitter {
1162
1205
  * });
1163
1206
  * console.log(`Deleted ${result.count} jobs`);
1164
1207
  * ```
1208
+ *
1209
+ * @see {@link JobManager.deleteJobs}
1165
1210
  */
1166
1211
  deleteJobs(filter: JobSelector): Promise<BulkOperationResult>;
1167
1212
  /**
@@ -1194,6 +1239,8 @@ declare class Monque extends EventEmitter {
1194
1239
  * res.json(job);
1195
1240
  * });
1196
1241
  * ```
1242
+ *
1243
+ * @see {@link JobQueryService.getJob}
1197
1244
  */
1198
1245
  getJob<T = unknown>(id: ObjectId): Promise<PersistedJob<T> | null>;
1199
1246
  /**
@@ -1237,6 +1284,8 @@ declare class Monque extends EventEmitter {
1237
1284
  * const jobs = await monque.getJobs();
1238
1285
  * const pendingRecurring = jobs.filter(job => isPendingJob(job) && isRecurringJob(job));
1239
1286
  * ```
1287
+ *
1288
+ * @see {@link JobQueryService.getJobs}
1240
1289
  */
1241
1290
  getJobs<T = unknown>(filter?: GetJobsFilter): Promise<PersistedJob<T>[]>;
1242
1291
  /**
@@ -1267,6 +1316,8 @@ declare class Monque extends EventEmitter {
1267
1316
  * });
1268
1317
  * }
1269
1318
  * ```
1319
+ *
1320
+ * @see {@link JobQueryService.getJobsWithCursor}
1270
1321
  */
1271
1322
  getJobsWithCursor<T = unknown>(options?: CursorOptions): Promise<CursorPage<T>>;
1272
1323
  /**
@@ -1275,6 +1326,9 @@ declare class Monque extends EventEmitter {
1275
1326
  * Uses MongoDB aggregation pipeline for efficient server-side calculation.
1276
1327
  * Returns counts per status and optional average processing duration for completed jobs.
1277
1328
  *
1329
+ * Results are cached per unique filter with a configurable TTL (default 5s).
1330
+ * Set `statsCacheTtlMs: 0` to disable caching.
1331
+ *
1278
1332
  * @param filter - Optional filter to scope statistics by job name
1279
1333
  * @returns Promise resolving to queue statistics
1280
1334
  * @throws {AggregationTimeoutError} If aggregation exceeds 30 second timeout
@@ -1291,6 +1345,8 @@ declare class Monque extends EventEmitter {
1291
1345
  * const emailStats = await monque.getQueueStats({ name: 'send-email' });
1292
1346
  * console.log(`${emailStats.total} email jobs in queue`);
1293
1347
  * ```
1348
+ *
1349
+ * @see {@link JobQueryService.getQueueStats}
1294
1350
  */
1295
1351
  getQueueStats(filter?: Pick<JobSelector, 'name'>): Promise<QueueStats>;
1296
1352
  /**
@@ -1664,6 +1720,27 @@ declare class InvalidCursorError extends MonqueError {
1664
1720
  declare class AggregationTimeoutError extends MonqueError {
1665
1721
  constructor(message?: string);
1666
1722
  }
1723
+ /**
1724
+ * Error thrown when a job payload exceeds the configured maximum BSON byte size.
1725
+ *
1726
+ * @example
1727
+ * ```typescript
1728
+ * const monque = new Monque(db, { maxPayloadSize: 1_000_000 }); // 1 MB
1729
+ *
1730
+ * try {
1731
+ * await monque.enqueue('job', hugePayload);
1732
+ * } catch (error) {
1733
+ * if (error instanceof PayloadTooLargeError) {
1734
+ * console.error(`Payload ${error.actualSize} bytes exceeds limit ${error.maxSize} bytes`);
1735
+ * }
1736
+ * }
1737
+ * ```
1738
+ */
1739
+ declare class PayloadTooLargeError extends MonqueError {
1740
+ readonly actualSize: number;
1741
+ readonly maxSize: number;
1742
+ constructor(message: string, actualSize: number, maxSize: number);
1743
+ }
1667
1744
  //#endregion
1668
1745
  //#region src/shared/utils/backoff.d.ts
1669
1746
  /**
@@ -1753,5 +1830,5 @@ declare function getNextCronDate(expression: string, currentDate?: Date): Date;
1753
1830
  */
1754
1831
  declare function validateCronExpression(expression: string): void;
1755
1832
  //#endregion
1756
- export { AggregationTimeoutError, type BulkOperationResult, ConnectionError, CursorDirection, type CursorOptions, type CursorPage, DEFAULT_BASE_INTERVAL, DEFAULT_MAX_BACKOFF_DELAY, type EnqueueOptions, type GetJobsFilter, InvalidCronError, InvalidCursorError, type Job, type JobHandler, type JobSelector, JobStateError, JobStatus, type JobStatusType, Monque, MonqueError, type MonqueEventMap, type MonqueOptions, type PersistedJob, type QueueStats, type ScheduleOptions, ShutdownTimeoutError, type WorkerOptions, WorkerRegistrationError, calculateBackoff, calculateBackoffDelay, getNextCronDate, isCancelledJob, isCompletedJob, isFailedJob, isPendingJob, isPersistedJob, isProcessingJob, isRecurringJob, isValidJobStatus, validateCronExpression };
1833
+ export { AggregationTimeoutError, type BulkOperationResult, ConnectionError, CursorDirection, type CursorOptions, type CursorPage, DEFAULT_BASE_INTERVAL, DEFAULT_MAX_BACKOFF_DELAY, type EnqueueOptions, type GetJobsFilter, InvalidCronError, InvalidCursorError, type Job, type JobHandler, type JobSelector, JobStateError, JobStatus, type JobStatusType, Monque, MonqueError, type MonqueEventMap, type MonqueOptions, PayloadTooLargeError, type PersistedJob, type QueueStats, type ScheduleOptions, ShutdownTimeoutError, type WorkerOptions, WorkerRegistrationError, calculateBackoff, calculateBackoffDelay, getNextCronDate, isCancelledJob, isCompletedJob, isFailedJob, isPendingJob, isPersistedJob, isProcessingJob, isRecurringJob, isValidJobStatus, validateCronExpression };
1757
1834
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/jobs/types.ts","../src/jobs/guards.ts","../src/events/types.ts","../src/workers/types.ts","../src/scheduler/types.ts","../src/scheduler/monque.ts","../src/shared/errors.ts","../src/shared/utils/backoff.ts","../src/shared/utils/cron.ts"],"mappings":";;;;;;;AAmBA;;;;;;;;;;;AAgBA;;;cAhBa,SAAA;EAgBwD,8EA0BjD;EAAA,mCAEb;EAAA,iCASE;EAAA,2BAMG;EAAA;;;;;KA3CA,aAAA,WAAwB,SAAA,eAAwB,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;UA0B3C,GAAA;EAgEL;EA9DX,GAAA,GAAM,QAAA;EA8DiB;EA3DvB,IAAA;EA2DuC;EAxDvC,IAAA,EAAM,CAAA;EAwDyD;EArD/D,MAAA,EAAQ,aAAA;EAqDgB;EAlDxB,SAAA,EAAW,IAAA;EAkDgC;EA/C3C,QAAA,GAAW,IAAA;EA+C4C;;;AAaxD;;EArDC,SAAA;EA+DY;;;;;EAxDZ,aAAA,GAAgB,IAAA;EAqEA;;;;EA/DhB,iBAAA;EA4FgB;EAzFhB,SAAA;;EAGA,UAAA;EAwFA;EArFA,cAAA;EAwFS;EArFT,SAAA;EAwFA;EArFA,SAAA,EAAW,IAAA;EAwFP;EArFJ,SAAA,EAAW,IAAA;AAAA;;;;;;;KASA,YAAA,gBAA4B,GAAA,CAAI,CAAA;EAAO,GAAA,EAAK,QAAA;AAAA;;;;;;AAqGxD;;;;;AAKA;UA7FiB,cAAA;;;;AA6GjB;EAxGC,SAAA;;;;EAKA,KAAA,GAAQ,IAAA;AAAA;;;;;;;;;;;UAaQ,eAAA;EA0F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;EAAA,SACA,aAAA;EAAA,SACA,eAAA;cAHhB,OAAA,UACgB,KAAA,UACA,aAAA,UACA,eAAA;AAAA;;;;ANkElB;;;;;AAgBA;;;;;;cMzDa,kBAAA,SAA2B,WAAA;cAC3B,OAAA;AAAA;;;;;;;;;;;AN2Eb;;;;cMnDa,uBAAA,SAAgC,WAAA;cAChC,OAAA;AAAA;;;;;;;cCpNA,qBAAA;;;;;;;;cASA,yBAAA;;;APsBb;;;;;AA0BA;;;;;;;;;;;;;;;;;;iBOrBgB,gBAAA,CACf,SAAA,UACA,YAAA,WACA,QAAA,YACE,IAAA;;;;;;;;;iBAmBa,qBAAA,CACf,SAAA,UACA,YAAA,WACA,QAAA;;;;;;;AP/CD;;;;;;;;;;;AAgBA;;;;;AA0BA;;;iBQlCgB,eAAA,CAAgB,UAAA,UAAoB,WAAA,GAAc,IAAA,GAAO,IAAA;;;;;;;;;;;;iBAsBzD,sBAAA,CAAuB,UAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/jobs/types.ts","../src/jobs/guards.ts","../src/events/types.ts","../src/workers/types.ts","../src/scheduler/types.ts","../src/scheduler/monque.ts","../src/shared/errors.ts","../src/shared/utils/backoff.ts","../src/shared/utils/cron.ts"],"mappings":";;;;;;;AAmBA;;;;;;;;;;;AAgBA;;;cAhBa,SAAA;EAgBwD,8EA0BjD;EAAA,mCAEb;EAAA,iCASE;EAAA,2BAMG;EAAA;;;;;KA3CA,aAAA,WAAwB,SAAA,eAAwB,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;UA0B3C,GAAA;EAgEL;EA9DX,GAAA,GAAM,QAAA;EA8DiB;EA3DvB,IAAA;EA2DuC;EAxDvC,IAAA,EAAM,CAAA;EAwDyD;EArD/D,MAAA,EAAQ,aAAA;EAqDgB;EAlDxB,SAAA,EAAW,IAAA;EAkDgC;EA/C3C,QAAA,GAAW,IAAA;EA+C4C;;;AAaxD;;EArDC,SAAA;EA+DY;;;;;EAxDZ,aAAA,G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AAA"}
package/dist/index.d.mts CHANGED
@@ -578,16 +578,16 @@ interface MonqueEventMap {
578
578
  };
579
579
  /**
580
580
  * Emitted when multiple jobs are cancelled in bulk.
581
+ * Contains only the count of affected jobs (no individual IDs for O(1) performance).
581
582
  */
582
583
  'jobs:cancelled': {
583
- jobIds: string[];
584
584
  count: number;
585
585
  };
586
586
  /**
587
587
  * Emitted when multiple jobs are retried in bulk.
588
+ * Contains only the count of affected jobs (no individual IDs for O(1) performance).
588
589
  */
589
590
  'jobs:retried': {
590
- jobIds: string[];
591
591
  count: number;
592
592
  };
593
593
  /**
@@ -780,6 +780,27 @@ interface MonqueOptions {
780
780
  * @default false
781
781
  */
782
782
  skipIndexCreation?: boolean;
783
+ /**
784
+ * Maximum allowed BSON byte size for job data payloads.
785
+ *
786
+ * When set, `enqueue()`, `now()`, and `schedule()` validate the payload size
787
+ * using `BSON.calculateObjectSize()` before insertion. Jobs exceeding this limit
788
+ * throw `PayloadTooLargeError`.
789
+ *
790
+ * When undefined, no size validation occurs.
791
+ */
792
+ maxPayloadSize?: number | undefined;
793
+ /**
794
+ * TTL in milliseconds for getQueueStats() result caching.
795
+ *
796
+ * When set to a positive value, repeated getQueueStats() calls with the same
797
+ * filter return cached results instead of re-executing the aggregation pipeline.
798
+ * Each unique filter (job name) maintains its own cache entry.
799
+ *
800
+ * Set to 0 to disable caching entirely.
801
+ * @default 5000
802
+ */
803
+ statsCacheTtlMs?: number;
783
804
  }
784
805
  //#endregion
785
806
  //#region src/scheduler/monque.d.ts
@@ -852,9 +873,6 @@ declare class Monque extends EventEmitter {
852
873
  private readonly options;
853
874
  private collection;
854
875
  private workers;
855
- private pollIntervalId;
856
- private heartbeatIntervalId;
857
- private cleanupIntervalId;
858
876
  private isRunning;
859
877
  private isInitialized;
860
878
  private _scheduler;
@@ -862,6 +880,7 @@ declare class Monque extends EventEmitter {
862
880
  private _query;
863
881
  private _processor;
864
882
  private _changeStreamHandler;
883
+ private _lifecycleManager;
865
884
  constructor(db: Db, options?: MonqueOptions);
866
885
  /**
867
886
  * Initialize the scheduler by setting up the MongoDB collection and indexes.
@@ -880,6 +899,8 @@ declare class Monque extends EventEmitter {
880
899
  private get processor();
881
900
  /** @throws {ConnectionError} if not initialized */
882
901
  private get changeStreamHandler();
902
+ /** @throws {ConnectionError} if not initialized */
903
+ private get lifecycleManager();
883
904
  /**
884
905
  * Build the shared context for internal services.
885
906
  */
@@ -904,16 +925,15 @@ declare class Monque extends EventEmitter {
904
925
  */
905
926
  private recoverStaleJobs;
906
927
  /**
907
- * Clean up old completed and failed jobs based on retention policy.
908
- *
909
- * - Removes completed jobs older than `jobRetention.completed`
910
- * - Removes failed jobs older than `jobRetention.failed`
928
+ * Check if another active instance is using the same schedulerInstanceId.
929
+ * Uses heartbeat staleness to distinguish active instances from crashed ones.
911
930
  *
912
- * The cleanup runs concurrently for both statuses if configured.
931
+ * Called after stale recovery to avoid false positives: stale recovery resets
932
+ * jobs with old `lockedAt`, so only jobs with recent heartbeats remain.
913
933
  *
914
- * @returns Promise resolving when all deletion operations complete
934
+ * @throws {ConnectionError} If an active instance with the same ID is detected
915
935
  */
916
- private cleanupJobs;
936
+ private checkInstanceCollision;
917
937
  /**
918
938
  * Enqueue a job for processing.
919
939
  *
@@ -932,6 +952,7 @@ declare class Monque extends EventEmitter {
932
952
  * @param options - Scheduling and deduplication options
933
953
  * @returns Promise resolving to the created or existing job document
934
954
  * @throws {ConnectionError} If database operation fails or scheduler not initialized
955
+ * @throws {PayloadTooLargeError} If payload exceeds configured `maxPayloadSize`
935
956
  *
936
957
  * @example Basic job enqueueing
937
958
  * ```typescript
@@ -957,6 +978,8 @@ declare class Monque extends EventEmitter {
957
978
  * });
958
979
  * // Subsequent enqueues with same uniqueKey return existing pending/processing job
959
980
  * ```
981
+ *
982
+ * @see {@link JobScheduler.enqueue}
960
983
  */
961
984
  enqueue<T>(name: string, data: T, options?: EnqueueOptions): Promise<PersistedJob<T>>;
962
985
  /**
@@ -986,6 +1009,8 @@ declare class Monque extends EventEmitter {
986
1009
  * await monque.now('process-order', { orderId: order.id });
987
1010
  * return order; // Return immediately, processing happens async
988
1011
  * ```
1012
+ *
1013
+ * @see {@link JobScheduler.now}
989
1014
  */
990
1015
  now<T>(name: string, data: T): Promise<PersistedJob<T>>;
991
1016
  /**
@@ -1008,6 +1033,7 @@ declare class Monque extends EventEmitter {
1008
1033
  * @returns Promise resolving to the created job document with `repeatInterval` set
1009
1034
  * @throws {InvalidCronError} If cron expression is invalid
1010
1035
  * @throws {ConnectionError} If database operation fails or scheduler not initialized
1036
+ * @throws {PayloadTooLargeError} If payload exceeds configured `maxPayloadSize`
1011
1037
  *
1012
1038
  * @example Hourly cleanup job
1013
1039
  * ```typescript
@@ -1031,6 +1057,8 @@ declare class Monque extends EventEmitter {
1031
1057
  * recipients: ['analytics@example.com']
1032
1058
  * });
1033
1059
  * ```
1060
+ *
1061
+ * @see {@link JobScheduler.schedule}
1034
1062
  */
1035
1063
  schedule<T>(cron: string, name: string, data: T, options?: ScheduleOptions): Promise<PersistedJob<T>>;
1036
1064
  /**
@@ -1049,6 +1077,8 @@ declare class Monque extends EventEmitter {
1049
1077
  * const job = await monque.enqueue('report', { type: 'daily' });
1050
1078
  * await monque.cancelJob(job._id.toString());
1051
1079
  * ```
1080
+ *
1081
+ * @see {@link JobManager.cancelJob}
1052
1082
  */
1053
1083
  cancelJob(jobId: string): Promise<PersistedJob<unknown> | null>;
1054
1084
  /**
@@ -1068,6 +1098,8 @@ declare class Monque extends EventEmitter {
1068
1098
  * await monque.retryJob(job._id.toString());
1069
1099
  * });
1070
1100
  * ```
1101
+ *
1102
+ * @see {@link JobManager.retryJob}
1071
1103
  */
1072
1104
  retryJob(jobId: string): Promise<PersistedJob<unknown> | null>;
1073
1105
  /**
@@ -1085,6 +1117,8 @@ declare class Monque extends EventEmitter {
1085
1117
  * const nextHour = new Date(Date.now() + 60 * 60 * 1000);
1086
1118
  * await monque.rescheduleJob(jobId, nextHour);
1087
1119
  * ```
1120
+ *
1121
+ * @see {@link JobManager.rescheduleJob}
1088
1122
  */
1089
1123
  rescheduleJob(jobId: string, runAt: Date): Promise<PersistedJob<unknown> | null>;
1090
1124
  /**
@@ -1103,17 +1137,20 @@ declare class Monque extends EventEmitter {
1103
1137
  * console.log('Job permanently removed');
1104
1138
  * }
1105
1139
  * ```
1140
+ *
1141
+ * @see {@link JobManager.deleteJob}
1106
1142
  */
1107
1143
  deleteJob(jobId: string): Promise<boolean>;
1108
1144
  /**
1109
- * Cancel multiple jobs matching the given filter.
1145
+ * Cancel multiple jobs matching the given filter via a single updateMany call.
1110
1146
  *
1111
- * Only cancels jobs in 'pending' status. Jobs in other states are collected
1112
- * as errors in the result. Emits a 'jobs:cancelled' event with the IDs of
1147
+ * Only cancels jobs in 'pending' status the status guard is applied regardless
1148
+ * of what the filter specifies. Jobs in other states are silently skipped (not
1149
+ * matched by the query). Emits a 'jobs:cancelled' event with the count of
1113
1150
  * successfully cancelled jobs.
1114
1151
  *
1115
1152
  * @param filter - Selector for which jobs to cancel (name, status, date range)
1116
- * @returns Result with count of cancelled jobs and any errors encountered
1153
+ * @returns Result with count of cancelled jobs (errors array always empty for bulk ops)
1117
1154
  *
1118
1155
  * @example Cancel all pending jobs for a queue
1119
1156
  * ```typescript
@@ -1123,17 +1160,20 @@ declare class Monque extends EventEmitter {
1123
1160
  * });
1124
1161
  * console.log(`Cancelled ${result.count} jobs`);
1125
1162
  * ```
1163
+ *
1164
+ * @see {@link JobManager.cancelJobs}
1126
1165
  */
1127
1166
  cancelJobs(filter: JobSelector): Promise<BulkOperationResult>;
1128
1167
  /**
1129
- * Retry multiple jobs matching the given filter.
1168
+ * Retry multiple jobs matching the given filter via a single pipeline-style updateMany call.
1130
1169
  *
1131
- * Only retries jobs in 'failed' or 'cancelled' status. Jobs in other states
1132
- * are collected as errors in the result. Emits a 'jobs:retried' event with
1133
- * the IDs of successfully retried jobs.
1170
+ * Only retries jobs in 'failed' or 'cancelled' status the status guard is applied
1171
+ * regardless of what the filter specifies. Jobs in other states are silently skipped.
1172
+ * Uses `$rand` for per-document staggered `nextRunAt` to avoid thundering herd on retry.
1173
+ * Emits a 'jobs:retried' event with the count of successfully retried jobs.
1134
1174
  *
1135
1175
  * @param filter - Selector for which jobs to retry (name, status, date range)
1136
- * @returns Result with count of retried jobs and any errors encountered
1176
+ * @returns Result with count of retried jobs (errors array always empty for bulk ops)
1137
1177
  *
1138
1178
  * @example Retry all failed jobs
1139
1179
  * ```typescript
@@ -1142,12 +1182,15 @@ declare class Monque extends EventEmitter {
1142
1182
  * });
1143
1183
  * console.log(`Retried ${result.count} jobs`);
1144
1184
  * ```
1185
+ *
1186
+ * @see {@link JobManager.retryJobs}
1145
1187
  */
1146
1188
  retryJobs(filter: JobSelector): Promise<BulkOperationResult>;
1147
1189
  /**
1148
1190
  * Delete multiple jobs matching the given filter.
1149
1191
  *
1150
1192
  * Deletes jobs in any status. Uses a batch delete for efficiency.
1193
+ * Emits a 'jobs:deleted' event with the count of deleted jobs.
1151
1194
  * Does not emit individual 'job:deleted' events to avoid noise.
1152
1195
  *
1153
1196
  * @param filter - Selector for which jobs to delete (name, status, date range)
@@ -1162,6 +1205,8 @@ declare class Monque extends EventEmitter {
1162
1205
  * });
1163
1206
  * console.log(`Deleted ${result.count} jobs`);
1164
1207
  * ```
1208
+ *
1209
+ * @see {@link JobManager.deleteJobs}
1165
1210
  */
1166
1211
  deleteJobs(filter: JobSelector): Promise<BulkOperationResult>;
1167
1212
  /**
@@ -1194,6 +1239,8 @@ declare class Monque extends EventEmitter {
1194
1239
  * res.json(job);
1195
1240
  * });
1196
1241
  * ```
1242
+ *
1243
+ * @see {@link JobQueryService.getJob}
1197
1244
  */
1198
1245
  getJob<T = unknown>(id: ObjectId): Promise<PersistedJob<T> | null>;
1199
1246
  /**
@@ -1237,6 +1284,8 @@ declare class Monque extends EventEmitter {
1237
1284
  * const jobs = await monque.getJobs();
1238
1285
  * const pendingRecurring = jobs.filter(job => isPendingJob(job) && isRecurringJob(job));
1239
1286
  * ```
1287
+ *
1288
+ * @see {@link JobQueryService.getJobs}
1240
1289
  */
1241
1290
  getJobs<T = unknown>(filter?: GetJobsFilter): Promise<PersistedJob<T>[]>;
1242
1291
  /**
@@ -1267,6 +1316,8 @@ declare class Monque extends EventEmitter {
1267
1316
  * });
1268
1317
  * }
1269
1318
  * ```
1319
+ *
1320
+ * @see {@link JobQueryService.getJobsWithCursor}
1270
1321
  */
1271
1322
  getJobsWithCursor<T = unknown>(options?: CursorOptions): Promise<CursorPage<T>>;
1272
1323
  /**
@@ -1275,6 +1326,9 @@ declare class Monque extends EventEmitter {
1275
1326
  * Uses MongoDB aggregation pipeline for efficient server-side calculation.
1276
1327
  * Returns counts per status and optional average processing duration for completed jobs.
1277
1328
  *
1329
+ * Results are cached per unique filter with a configurable TTL (default 5s).
1330
+ * Set `statsCacheTtlMs: 0` to disable caching.
1331
+ *
1278
1332
  * @param filter - Optional filter to scope statistics by job name
1279
1333
  * @returns Promise resolving to queue statistics
1280
1334
  * @throws {AggregationTimeoutError} If aggregation exceeds 30 second timeout
@@ -1291,6 +1345,8 @@ declare class Monque extends EventEmitter {
1291
1345
  * const emailStats = await monque.getQueueStats({ name: 'send-email' });
1292
1346
  * console.log(`${emailStats.total} email jobs in queue`);
1293
1347
  * ```
1348
+ *
1349
+ * @see {@link JobQueryService.getQueueStats}
1294
1350
  */
1295
1351
  getQueueStats(filter?: Pick<JobSelector, 'name'>): Promise<QueueStats>;
1296
1352
  /**
@@ -1664,6 +1720,27 @@ declare class InvalidCursorError extends MonqueError {
1664
1720
  declare class AggregationTimeoutError extends MonqueError {
1665
1721
  constructor(message?: string);
1666
1722
  }
1723
+ /**
1724
+ * Error thrown when a job payload exceeds the configured maximum BSON byte size.
1725
+ *
1726
+ * @example
1727
+ * ```typescript
1728
+ * const monque = new Monque(db, { maxPayloadSize: 1_000_000 }); // 1 MB
1729
+ *
1730
+ * try {
1731
+ * await monque.enqueue('job', hugePayload);
1732
+ * } catch (error) {
1733
+ * if (error instanceof PayloadTooLargeError) {
1734
+ * console.error(`Payload ${error.actualSize} bytes exceeds limit ${error.maxSize} bytes`);
1735
+ * }
1736
+ * }
1737
+ * ```
1738
+ */
1739
+ declare class PayloadTooLargeError extends MonqueError {
1740
+ readonly actualSize: number;
1741
+ readonly maxSize: number;
1742
+ constructor(message: string, actualSize: number, maxSize: number);
1743
+ }
1667
1744
  //#endregion
1668
1745
  //#region src/shared/utils/backoff.d.ts
1669
1746
  /**
@@ -1753,5 +1830,5 @@ declare function getNextCronDate(expression: string, currentDate?: Date): Date;
1753
1830
  */
1754
1831
  declare function validateCronExpression(expression: string): void;
1755
1832
  //#endregion
1756
- export { AggregationTimeoutError, type BulkOperationResult, ConnectionError, CursorDirection, type CursorOptions, type CursorPage, DEFAULT_BASE_INTERVAL, DEFAULT_MAX_BACKOFF_DELAY, type EnqueueOptions, type GetJobsFilter, InvalidCronError, InvalidCursorError, type Job, type JobHandler, type JobSelector, JobStateError, JobStatus, type JobStatusType, Monque, MonqueError, type MonqueEventMap, type MonqueOptions, type PersistedJob, type QueueStats, type ScheduleOptions, ShutdownTimeoutError, type WorkerOptions, WorkerRegistrationError, calculateBackoff, calculateBackoffDelay, getNextCronDate, isCancelledJob, isCompletedJob, isFailedJob, isPendingJob, isPersistedJob, isProcessingJob, isRecurringJob, isValidJobStatus, validateCronExpression };
1833
+ export { AggregationTimeoutError, type BulkOperationResult, ConnectionError, CursorDirection, type CursorOptions, type CursorPage, DEFAULT_BASE_INTERVAL, DEFAULT_MAX_BACKOFF_DELAY, type EnqueueOptions, type GetJobsFilter, InvalidCronError, InvalidCursorError, type Job, type JobHandler, type JobSelector, JobStateError, JobStatus, type JobStatusType, Monque, MonqueError, type MonqueEventMap, type MonqueOptions, PayloadTooLargeError, type PersistedJob, type QueueStats, type ScheduleOptions, ShutdownTimeoutError, type WorkerOptions, WorkerRegistrationError, calculateBackoff, calculateBackoffDelay, getNextCronDate, isCancelledJob, isCompletedJob, isFailedJob, isPendingJob, isPersistedJob, isProcessingJob, isRecurringJob, isValidJobStatus, validateCronExpression };
1757
1834
  //# sourceMappingURL=index.d.mts.map