@gravito/stream 1.0.0-beta.1 → 1.0.0-beta.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.
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { GravitoOrbit, PlanetCore } from 'gravito-core';
1
+ import { GravitoOrbit, PlanetCore } from '@gravito/core';
2
2
 
3
3
  /**
4
4
  * Serialized job payload.
@@ -36,6 +36,30 @@ interface SerializedJob {
36
36
  * Maximum attempts.
37
37
  */
38
38
  maxAttempts?: number;
39
+ /**
40
+ * Group ID for FIFO ordering.
41
+ */
42
+ groupId?: string;
43
+ /**
44
+ * Initial retry delay (seconds).
45
+ */
46
+ retryAfterSeconds?: number;
47
+ /**
48
+ * Retry delay multiplier.
49
+ */
50
+ retryMultiplier?: number;
51
+ /**
52
+ * Last error message.
53
+ */
54
+ error?: string;
55
+ /**
56
+ * Timestamp when the job failed permanently.
57
+ */
58
+ failedAt?: number;
59
+ /**
60
+ * Job priority.
61
+ */
62
+ priority?: string | number;
39
63
  }
40
64
  /**
41
65
  * Topic options (for Kafka, etc.).
@@ -83,6 +107,119 @@ interface QueueConfig {
83
107
  * Default serializer type.
84
108
  */
85
109
  defaultSerializer?: 'json' | 'class';
110
+ /**
111
+ * Persistence configuration (SQL Archive).
112
+ */
113
+ persistence?: {
114
+ /**
115
+ * Persistence adapter instance or config.
116
+ */
117
+ adapter: PersistenceAdapter;
118
+ /**
119
+ * Whether to automatically archive completed jobs.
120
+ */
121
+ archiveCompleted?: boolean;
122
+ /**
123
+ * Whether to automatically archive failed jobs.
124
+ */
125
+ archiveFailed?: boolean;
126
+ /**
127
+ * Whether to archive jobs immediately upon enqueue (Audit Mode).
128
+ * @default false
129
+ */
130
+ archiveEnqueued?: boolean;
131
+ };
132
+ }
133
+ /**
134
+ * Persistence Adapter Interface
135
+ * Used for long-term archiving of jobs in a SQL database.
136
+ */
137
+ interface PersistenceAdapter {
138
+ /**
139
+ * Archive a job.
140
+ */
141
+ archive(queue: string, job: SerializedJob, status: 'completed' | 'failed' | 'waiting' | string): Promise<void>;
142
+ /**
143
+ * Find a job in the archive.
144
+ */
145
+ find(queue: string, id: string): Promise<SerializedJob | null>;
146
+ /**
147
+ * List jobs from the archive.
148
+ */
149
+ /**
150
+ * List jobs from the archive.
151
+ */
152
+ list(queue: string, options?: {
153
+ limit?: number;
154
+ offset?: number;
155
+ status?: 'completed' | 'failed' | 'waiting' | string;
156
+ jobId?: string;
157
+ startTime?: Date;
158
+ endTime?: Date;
159
+ }): Promise<SerializedJob[]>;
160
+ /**
161
+ * Remove old data from the archive.
162
+ */
163
+ cleanup(days: number): Promise<number>;
164
+ /**
165
+ * Count jobs in the archive.
166
+ */
167
+ count(queue: string, options?: {
168
+ status?: 'completed' | 'failed' | 'waiting' | string;
169
+ jobId?: string;
170
+ startTime?: Date;
171
+ endTime?: Date;
172
+ }): Promise<number>;
173
+ /**
174
+ * Archive a system log message.
175
+ */
176
+ archiveLog(log: {
177
+ level: string;
178
+ message: string;
179
+ workerId: string;
180
+ queue?: string;
181
+ timestamp: Date;
182
+ }): Promise<void>;
183
+ /**
184
+ * List system logs from the archive.
185
+ */
186
+ listLogs(options?: {
187
+ limit?: number;
188
+ offset?: number;
189
+ level?: string;
190
+ workerId?: string;
191
+ queue?: string;
192
+ search?: string;
193
+ startTime?: Date;
194
+ endTime?: Date;
195
+ }): Promise<any[]>;
196
+ /**
197
+ * Count system logs in the archive.
198
+ */
199
+ countLogs(options?: {
200
+ level?: string;
201
+ workerId?: string;
202
+ queue?: string;
203
+ search?: string;
204
+ startTime?: Date;
205
+ endTime?: Date;
206
+ }): Promise<number>;
207
+ }
208
+ /**
209
+ * Options when pushing a job.
210
+ */
211
+ interface JobPushOptions {
212
+ /**
213
+ * Group ID for FIFO ordering (e.g. userId).
214
+ * If set, jobs with the same groupId will be processed strictly sequentially.
215
+ */
216
+ groupId?: string;
217
+ /**
218
+ * Job priority.
219
+ * Higher priority jobs are processed first (if supported by driver).
220
+ * Example: 'high', 'low', 'critical'
221
+ */
222
+ priority?: string | number;
86
223
  }
87
224
 
88
225
  /**
@@ -94,7 +231,7 @@ interface QueueConfig {
94
231
  * @example
95
232
  * ```typescript
96
233
  * class MyDriver implements QueueDriver {
97
- * async push(queue: string, job: SerializedJob): Promise<void> {
234
+ * async push(queue: string, job: SerializedJob, options?: JobPushOptions): Promise<void> {
98
235
  * // push a job
99
236
  * }
100
237
  *
@@ -102,6 +239,10 @@ interface QueueConfig {
102
239
  * // pop a job
103
240
  * }
104
241
  *
242
+ * async complete(queue: string, job: SerializedJob): Promise<void> {
243
+ * // job completed (for FIFO handling)
244
+ * }
245
+ *
105
246
  * async size(queue: string): Promise<number> {
106
247
  * // queue size
107
248
  * }
@@ -117,14 +258,21 @@ interface QueueDriver {
117
258
  * Push a job to a queue.
118
259
  * @param queue - Queue name
119
260
  * @param job - Serialized job
261
+ * @param options - Push options (e.g. groupId)
120
262
  */
121
- push(queue: string, job: SerializedJob): Promise<void>;
263
+ push(queue: string, job: SerializedJob, options?: JobPushOptions): Promise<void>;
122
264
  /**
123
265
  * Pop a job from a queue (non-blocking).
124
266
  * @param queue - Queue name
125
267
  * @returns Serialized job, or `null` if the queue is empty
126
268
  */
127
269
  pop(queue: string): Promise<SerializedJob | null>;
270
+ /**
271
+ * Mark a job as completed (used for FIFO/Group handling).
272
+ * @param queue - Queue name
273
+ * @param job - Serialized job
274
+ */
275
+ complete?(queue: string, job: SerializedJob): Promise<void>;
128
276
  /**
129
277
  * Get queue size.
130
278
  * @param queue - Queue name
@@ -136,6 +284,12 @@ interface QueueDriver {
136
284
  * @param queue - Queue name
137
285
  */
138
286
  clear(queue: string): Promise<void>;
287
+ /**
288
+ * Mark a job as permanently failed (move to DLQ).
289
+ * @param queue - Queue name
290
+ * @param job - Serialized job with error info
291
+ */
292
+ fail?(queue: string, job: SerializedJob): Promise<void>;
139
293
  /**
140
294
  * Push multiple jobs (optional, higher throughput).
141
295
  * @param queue - Queue name
@@ -171,6 +325,48 @@ interface QueueDriver {
171
325
  * @param topic - Topic name
172
326
  */
173
327
  deleteTopic?(topic: string): Promise<void>;
328
+ /**
329
+ * Report worker heartbeat for monitoring.
330
+ * @param workerInfo - Worker information
331
+ * @param prefix - Optional prefix for monitoring keys
332
+ */
333
+ reportHeartbeat?(workerInfo: any, prefix?: string): Promise<void>;
334
+ /**
335
+ * Publish a log message for monitoring.
336
+ * @param logPayload - Log payload
337
+ * @param prefix - Optional prefix for monitoring channels/keys
338
+ */
339
+ publishLog?(logPayload: any, prefix?: string): Promise<void>;
340
+ /**
341
+ * Check if a queue is rate limited.
342
+ * @param queue - Queue name
343
+ * @param config - Rate limit configuration
344
+ * @returns true if allowed, false if limited
345
+ */
346
+ checkRateLimit?(queue: string, config: {
347
+ max: number;
348
+ duration: number;
349
+ }): Promise<boolean>;
350
+ /**
351
+ * Retry failed jobs from DLQ.
352
+ * @param queue - Queue name
353
+ * @param count - Optional count (default: all)
354
+ * @returns Number of jobs retried
355
+ */
356
+ retryFailed?(queue: string, count?: number): Promise<number>;
357
+ /**
358
+ * Get failed jobs from DLQ.
359
+ * @param queue - Queue name
360
+ * @param start - Start index
361
+ * @param end - End index
362
+ * @returns Array of failed jobs
363
+ */
364
+ getFailed?(queue: string, start?: number, end?: number): Promise<SerializedJob[]>;
365
+ /**
366
+ * Clear failed jobs from DLQ.
367
+ * @param queue - Queue name
368
+ */
369
+ clearFailed?(queue: string): Promise<void>;
174
370
  }
175
371
 
176
372
  /**
@@ -216,6 +412,10 @@ interface Queueable {
216
412
  * Delay before execution (seconds).
217
413
  */
218
414
  delaySeconds?: number;
415
+ /**
416
+ * Job priority.
417
+ */
418
+ priority?: string | number;
219
419
  /**
220
420
  * Set target queue.
221
421
  * @param queue - Queue name
@@ -228,6 +428,12 @@ interface Queueable {
228
428
  * @returns Self for fluent chaining
229
429
  */
230
430
  onConnection(connection: string): this;
431
+ /**
432
+ * Set job priority.
433
+ * @param priority - Priority level
434
+ * @returns Self for fluent chaining
435
+ */
436
+ withPriority(priority: string | number): this;
231
437
  /**
232
438
  * Set delay (seconds).
233
439
  * @param delay - Delay seconds
@@ -262,6 +468,10 @@ interface Queueable {
262
468
  * ```
263
469
  */
264
470
  declare abstract class Job implements Queueable {
471
+ /**
472
+ * Unique job identifier.
473
+ */
474
+ id?: string;
265
475
  /**
266
476
  * Queue name.
267
477
  */
@@ -282,6 +492,22 @@ declare abstract class Job implements Queueable {
282
492
  * Maximum attempts.
283
493
  */
284
494
  maxAttempts?: number;
495
+ /**
496
+ * Group ID for FIFO.
497
+ */
498
+ groupId?: string;
499
+ /**
500
+ * Job priority.
501
+ */
502
+ priority?: string | number;
503
+ /**
504
+ * Initial retry delay (seconds).
505
+ */
506
+ retryAfterSeconds?: number;
507
+ /**
508
+ * Retry delay multiplier.
509
+ */
510
+ retryMultiplier?: number;
285
511
  /**
286
512
  * Set target queue.
287
513
  */
@@ -290,10 +516,27 @@ declare abstract class Job implements Queueable {
290
516
  * Set target connection.
291
517
  */
292
518
  onConnection(connection: string): this;
519
+ /**
520
+ * Set job priority.
521
+ * @param priority - 'high', 'low', or number
522
+ */
523
+ withPriority(priority: string | number): this;
293
524
  /**
294
525
  * Set delay (seconds).
295
526
  */
296
527
  delay(delay: number): this;
528
+ /**
529
+ * Set retry backoff strategy.
530
+ * @param seconds - Initial delay in seconds
531
+ * @param multiplier - Multiplier for each subsequent attempt (default: 2)
532
+ */
533
+ backoff(seconds: number, multiplier?: number): this;
534
+ /**
535
+ * Calculate retry delay for the next attempt.
536
+ * @param attempt - Current attempt number (1-based)
537
+ * @returns Delay in milliseconds
538
+ */
539
+ getRetryDelay(attempt: number): number;
297
540
  /**
298
541
  * Job handler logic.
299
542
  *
@@ -369,6 +612,8 @@ declare class QueueManager {
369
612
  private serializers;
370
613
  private defaultConnection;
371
614
  private defaultSerializer;
615
+ private persistence?;
616
+ private scheduler?;
372
617
  constructor(config?: QueueConfig);
373
618
  /**
374
619
  * Register a connection.
@@ -382,6 +627,11 @@ declare class QueueManager {
382
627
  * @returns Driver instance
383
628
  */
384
629
  getDriver(connection: string): QueueDriver;
630
+ /**
631
+ * Get the default connection name.
632
+ * @returns Default connection name
633
+ */
634
+ getDefaultConnection(): string;
385
635
  /**
386
636
  * Get a serializer.
387
637
  * @param type - Serializer type
@@ -398,6 +648,7 @@ declare class QueueManager {
398
648
  *
399
649
  * @template T - The type of the job.
400
650
  * @param job - Job instance to push.
651
+ * @param options - Push options.
401
652
  * @returns The same job instance (for fluent chaining).
402
653
  *
403
654
  * @example
@@ -405,7 +656,7 @@ declare class QueueManager {
405
656
  * await manager.push(new SendEmailJob('user@example.com'));
406
657
  * ```
407
658
  */
408
- push<T extends Job & Queueable>(job: T): Promise<T>;
659
+ push<T extends Job & Queueable>(job: T, options?: JobPushOptions): Promise<T>;
409
660
  /**
410
661
  * Push multiple jobs to the queue.
411
662
  *
@@ -447,6 +698,37 @@ declare class QueueManager {
447
698
  * @param connection - Connection name (optional).
448
699
  */
449
700
  clear(queue?: string, connection?: string): Promise<void>;
701
+ /**
702
+ * Mark a job as completed.
703
+ * @param job - Job instance
704
+ */
705
+ complete<T extends Job & Queueable>(job: T): Promise<void>;
706
+ /**
707
+ * Mark a job as permanently failed.
708
+ * @param job - Job instance
709
+ * @param error - Error object
710
+ */
711
+ fail<T extends Job & Queueable>(job: T, error: Error): Promise<void>;
712
+ /**
713
+ * Get the persistence adapter if configured.
714
+ */
715
+ getPersistence(): any;
716
+ /**
717
+ * Get the scheduler if configured.
718
+ */
719
+ getScheduler(): any;
720
+ /**
721
+ * Get failed jobs from DLQ (if driver supports it).
722
+ */
723
+ getFailed(queue: string, start?: number, end?: number, connection?: string): Promise<SerializedJob[]>;
724
+ /**
725
+ * Retry failed jobs from DLQ (if driver supports it).
726
+ */
727
+ retryFailed(queue: string, count?: number, connection?: string): Promise<number>;
728
+ /**
729
+ * Clear failed jobs from DLQ (if driver supports it).
730
+ */
731
+ clearFailed(queue: string, connection?: string): Promise<void>;
450
732
  }
451
733
 
452
734
  /**
@@ -520,6 +802,31 @@ interface ConsumerOptions {
520
802
  * Whether to keep polling when queues are empty.
521
803
  */
522
804
  keepAlive?: boolean;
805
+ /**
806
+ * Monitoring options.
807
+ */
808
+ monitor?: boolean | {
809
+ /**
810
+ * Heartbeat interval (milliseconds). Default: 5000.
811
+ */
812
+ interval?: number;
813
+ /**
814
+ * Extra info to report with heartbeat.
815
+ */
816
+ extraInfo?: Record<string, any>;
817
+ /**
818
+ * Prefix for monitoring keys/channels.
819
+ */
820
+ prefix?: string;
821
+ };
822
+ /**
823
+ * Rate limits per queue.
824
+ * Example: { 'emails': { max: 10, duration: 1000 } }
825
+ */
826
+ rateLimits?: Record<string, {
827
+ max: number;
828
+ duration: number;
829
+ }>;
523
830
  }
524
831
  /**
525
832
  * Consumer
@@ -546,11 +853,17 @@ declare class Consumer {
546
853
  private options;
547
854
  private running;
548
855
  private stopRequested;
856
+ private workerId;
857
+ private heartbeatTimer;
549
858
  constructor(queueManager: QueueManager, options: ConsumerOptions);
859
+ private get connectionName();
550
860
  /**
551
861
  * Start the consumer loop.
552
862
  */
553
863
  start(): Promise<void>;
864
+ private startHeartbeat;
865
+ private stopHeartbeat;
866
+ private publishLog;
554
867
  /**
555
868
  * Stop the consumer loop (graceful shutdown).
556
869
  */
@@ -633,6 +946,14 @@ declare class DatabaseDriver implements QueueDriver {
633
946
  * Push multiple jobs.
634
947
  */
635
948
  pushMany(queue: string, jobs: SerializedJob[]): Promise<void>;
949
+ /**
950
+ * Mark a job as failed (DLQ).
951
+ */
952
+ fail(queue: string, job: SerializedJob): Promise<void>;
953
+ /**
954
+ * Acknowledge/Complete a job.
955
+ */
956
+ complete(_queue: string, job: SerializedJob): Promise<void>;
636
957
  }
637
958
 
638
959
  /**
@@ -810,6 +1131,92 @@ declare class MemoryDriver implements QueueDriver {
810
1131
  popMany(queue: string, count: number): Promise<SerializedJob[]>;
811
1132
  }
812
1133
 
1134
+ /**
1135
+ * RabbitMQ driver configuration.
1136
+ */
1137
+ interface RabbitMQDriverConfig {
1138
+ /**
1139
+ * RabbitMQ client (amqplib) Connection or Channel.
1140
+ * If a Connection is provided, the driver will create and manage a Channel.
1141
+ */
1142
+ client: any;
1143
+ /**
1144
+ * Exchange name (optional).
1145
+ */
1146
+ exchange?: string;
1147
+ /**
1148
+ * Exchange type (default: 'fanout').
1149
+ */
1150
+ exchangeType?: 'direct' | 'topic' | 'headers' | 'fanout' | 'match';
1151
+ }
1152
+ /**
1153
+ * RabbitMQ Driver
1154
+ *
1155
+ * Uses RabbitMQ as the queue backend.
1156
+ * Implements FIFO via RabbitMQ Queues.
1157
+ *
1158
+ * Requires `amqplib`.
1159
+ *
1160
+ * @example
1161
+ * ```typescript
1162
+ * import amqp from 'amqplib'
1163
+ *
1164
+ * const connection = await amqp.connect('amqp://localhost')
1165
+ * const driver = new RabbitMQDriver({ client: connection })
1166
+ *
1167
+ * await driver.push('default', serializedJob)
1168
+ * ```
1169
+ */
1170
+ declare class RabbitMQDriver implements QueueDriver {
1171
+ private connection;
1172
+ private channel;
1173
+ private exchange?;
1174
+ private exchangeType;
1175
+ constructor(config: RabbitMQDriverConfig);
1176
+ /**
1177
+ * Ensure channel is created.
1178
+ */
1179
+ ensureChannel(): Promise<any>;
1180
+ /**
1181
+ * Get the underlying connection.
1182
+ */
1183
+ getRawConnection(): any;
1184
+ /**
1185
+ * Push a job (sendToQueue / publish).
1186
+ */
1187
+ push(queue: string, job: SerializedJob): Promise<void>;
1188
+ /**
1189
+ * Pop a job (get).
1190
+ */
1191
+ pop(queue: string): Promise<SerializedJob | null>;
1192
+ /**
1193
+ * Acknowledge a message.
1194
+ */
1195
+ acknowledge(messageId: string): Promise<void>;
1196
+ /**
1197
+ * Negative acknowledge a message.
1198
+ */
1199
+ nack(message: any, requeue?: boolean): Promise<void>;
1200
+ /**
1201
+ * Reject a message.
1202
+ */
1203
+ reject(message: any, requeue?: boolean): Promise<void>;
1204
+ /**
1205
+ * Subscribe to a queue.
1206
+ */
1207
+ subscribe(queue: string, callback: (job: SerializedJob) => Promise<void>, options?: {
1208
+ autoAck?: boolean;
1209
+ }): Promise<void>;
1210
+ /**
1211
+ * Get queue size.
1212
+ */
1213
+ size(queue: string): Promise<number>;
1214
+ /**
1215
+ * Clear a queue.
1216
+ */
1217
+ clear(queue: string): Promise<void>;
1218
+ }
1219
+
813
1220
  /**
814
1221
  * Redis driver configuration.
815
1222
  */
@@ -844,6 +1251,7 @@ interface RedisDriverConfig {
844
1251
  * import Redis from 'ioredis'
845
1252
  *
846
1253
  * const redis = new Redis('redis://localhost:6379')
1254
+ * const redis = new Redis('ioredis://localhost:6379')
847
1255
  * const driver = new RedisDriver({ client: redis })
848
1256
  *
849
1257
  * await driver.push('default', serializedJob)
@@ -852,6 +1260,8 @@ interface RedisDriverConfig {
852
1260
  declare class RedisDriver implements QueueDriver {
853
1261
  private prefix;
854
1262
  private client;
1263
+ private static PUSH_SCRIPT;
1264
+ private static COMPLETE_SCRIPT;
855
1265
  constructor(config: RedisDriverConfig);
856
1266
  /**
857
1267
  * Get full Redis key for a queue.
@@ -860,9 +1270,14 @@ declare class RedisDriver implements QueueDriver {
860
1270
  /**
861
1271
  * Push a job (LPUSH).
862
1272
  */
863
- push(queue: string, job: SerializedJob): Promise<void>;
1273
+ push(queue: string, job: SerializedJob, options?: JobPushOptions): Promise<void>;
1274
+ /**
1275
+ * Complete a job (handle Group FIFO).
1276
+ */
1277
+ complete(queue: string, job: SerializedJob): Promise<void>;
864
1278
  /**
865
1279
  * Pop a job (RPOP, FIFO).
1280
+ * Supports implicit priority polling (critical -> high -> default -> low).
866
1281
  */
867
1282
  pop(queue: string): Promise<SerializedJob | null>;
868
1283
  /**
@@ -873,6 +1288,10 @@ declare class RedisDriver implements QueueDriver {
873
1288
  * Get queue size.
874
1289
  */
875
1290
  size(queue: string): Promise<number>;
1291
+ /**
1292
+ * Mark a job as permanently failed (DLQ).
1293
+ */
1294
+ fail(queue: string, job: SerializedJob): Promise<void>;
876
1295
  /**
877
1296
  * Clear a queue.
878
1297
  */
@@ -885,6 +1304,35 @@ declare class RedisDriver implements QueueDriver {
885
1304
  * Pop multiple jobs.
886
1305
  */
887
1306
  popMany(queue: string, count: number): Promise<SerializedJob[]>;
1307
+ /**
1308
+ * Report worker heartbeat for monitoring.
1309
+ */
1310
+ reportHeartbeat(workerInfo: any, prefix?: string): Promise<void>;
1311
+ /**
1312
+ * Publish a log message for monitoring.
1313
+ */
1314
+ publishLog(logPayload: any, prefix?: string): Promise<void>;
1315
+ /**
1316
+ * Check if a queue is rate limited.
1317
+ * Uses a fixed window counter.
1318
+ */
1319
+ checkRateLimit(queue: string, config: {
1320
+ max: number;
1321
+ duration: number;
1322
+ }): Promise<boolean>;
1323
+ /**
1324
+ * Get failed jobs from DLQ.
1325
+ */
1326
+ getFailed(queue: string, start?: number, end?: number): Promise<SerializedJob[]>;
1327
+ /**
1328
+ * Retry failed jobs from DLQ.
1329
+ * Moves jobs from failed list back to the main queue.
1330
+ */
1331
+ retryFailed(queue: string, count?: number): Promise<number>;
1332
+ /**
1333
+ * Clear failed jobs from DLQ.
1334
+ */
1335
+ clearFailed(queue: string): Promise<void>;
888
1336
  }
889
1337
 
890
1338
  /**
@@ -1048,7 +1496,7 @@ declare class OrbitStream implements GravitoOrbit {
1048
1496
  */
1049
1497
  getQueueManager(): QueueManager | undefined;
1050
1498
  }
1051
- declare module 'gravito-core' {
1499
+ declare module '@gravito/core' {
1052
1500
  interface GravitoVariables {
1053
1501
  /** Queue manager for job processing */
1054
1502
  queue?: QueueManager;
@@ -1057,6 +1505,240 @@ declare module 'gravito-core' {
1057
1505
  }
1058
1506
  }
1059
1507
 
1508
+ /**
1509
+ * MySQL Persistence Adapter.
1510
+ * Archives jobs into a MySQL table for long-term auditing.
1511
+ */
1512
+ declare class MySQLPersistence implements PersistenceAdapter {
1513
+ private db;
1514
+ private table;
1515
+ private logsTable;
1516
+ /**
1517
+ * @param db - An Atlas DB instance or compatible QueryBuilder.
1518
+ * @param table - The name of the table to store archived jobs.
1519
+ */
1520
+ constructor(db: any, table?: string, logsTable?: string);
1521
+ /**
1522
+ * Archive a job.
1523
+ */
1524
+ archive(queue: string, job: SerializedJob, status: 'completed' | 'failed' | 'waiting' | string): Promise<void>;
1525
+ /**
1526
+ * Find a specific job in the archive.
1527
+ */
1528
+ find(queue: string, id: string): Promise<SerializedJob | null>;
1529
+ /**
1530
+ * List jobs from the archive.
1531
+ */
1532
+ list(queue: string, options?: {
1533
+ limit?: number;
1534
+ offset?: number;
1535
+ status?: 'completed' | 'failed' | 'waiting' | string;
1536
+ jobId?: string;
1537
+ startTime?: Date;
1538
+ endTime?: Date;
1539
+ }): Promise<SerializedJob[]>;
1540
+ /**
1541
+ * Search jobs from the archive.
1542
+ */
1543
+ search(query: string, options?: {
1544
+ limit?: number;
1545
+ offset?: number;
1546
+ queue?: string;
1547
+ }): Promise<SerializedJob[]>;
1548
+ /**
1549
+ * Archive a system log message.
1550
+ */
1551
+ archiveLog(log: {
1552
+ level: string;
1553
+ message: string;
1554
+ workerId: string;
1555
+ queue?: string;
1556
+ timestamp: Date;
1557
+ }): Promise<void>;
1558
+ /**
1559
+ * List system logs from the archive.
1560
+ */
1561
+ listLogs(options?: {
1562
+ limit?: number;
1563
+ offset?: number;
1564
+ level?: string;
1565
+ workerId?: string;
1566
+ queue?: string;
1567
+ search?: string;
1568
+ startTime?: Date;
1569
+ endTime?: Date;
1570
+ }): Promise<any[]>;
1571
+ /**
1572
+ * Count system logs in the archive.
1573
+ */
1574
+ countLogs(options?: {
1575
+ level?: string;
1576
+ workerId?: string;
1577
+ queue?: string;
1578
+ search?: string;
1579
+ startTime?: Date;
1580
+ endTime?: Date;
1581
+ }): Promise<number>;
1582
+ /**
1583
+ * Remove old records from the archive.
1584
+ */
1585
+ cleanup(days: number): Promise<number>;
1586
+ /**
1587
+ * Count jobs in the archive.
1588
+ */
1589
+ count(queue: string, options?: {
1590
+ status?: 'completed' | 'failed' | 'waiting' | string;
1591
+ jobId?: string;
1592
+ startTime?: Date;
1593
+ endTime?: Date;
1594
+ }): Promise<number>;
1595
+ /**
1596
+ * Help script to create the necessary table.
1597
+ */
1598
+ setupTable(): Promise<void>;
1599
+ private setupJobsTable;
1600
+ private setupLogsTable;
1601
+ }
1602
+
1603
+ /**
1604
+ * SQLite Persistence Adapter.
1605
+ * Archives jobs into a local SQLite database for zero-config persistence.
1606
+ */
1607
+ declare class SQLitePersistence implements PersistenceAdapter {
1608
+ private db;
1609
+ private table;
1610
+ private logsTable;
1611
+ /**
1612
+ * @param db - An Atlas DB instance (SQLite driver).
1613
+ * @param table - The name of the table to store archived jobs.
1614
+ */
1615
+ constructor(db: any, table?: string, logsTable?: string);
1616
+ /**
1617
+ * Archive a job.
1618
+ */
1619
+ archive(queue: string, job: SerializedJob, status: 'completed' | 'failed' | 'waiting' | string): Promise<void>;
1620
+ /**
1621
+ * Find a specific job in the archive.
1622
+ */
1623
+ find(queue: string, id: string): Promise<SerializedJob | null>;
1624
+ /**
1625
+ * List jobs from the archive.
1626
+ */
1627
+ list(queue: string, options?: {
1628
+ limit?: number;
1629
+ offset?: number;
1630
+ status?: 'completed' | 'failed' | 'waiting' | string;
1631
+ jobId?: string;
1632
+ startTime?: Date;
1633
+ endTime?: Date;
1634
+ }): Promise<SerializedJob[]>;
1635
+ /**
1636
+ * Search jobs from the archive.
1637
+ */
1638
+ search(query: string, options?: {
1639
+ limit?: number;
1640
+ offset?: number;
1641
+ queue?: string;
1642
+ }): Promise<SerializedJob[]>;
1643
+ /**
1644
+ * Archive a system log message.
1645
+ */
1646
+ archiveLog(log: {
1647
+ level: string;
1648
+ message: string;
1649
+ workerId: string;
1650
+ queue?: string;
1651
+ timestamp: Date;
1652
+ }): Promise<void>;
1653
+ /**
1654
+ * List system logs from the archive.
1655
+ */
1656
+ listLogs(options?: {
1657
+ limit?: number;
1658
+ offset?: number;
1659
+ level?: string;
1660
+ workerId?: string;
1661
+ queue?: string;
1662
+ search?: string;
1663
+ startTime?: Date;
1664
+ endTime?: Date;
1665
+ }): Promise<any[]>;
1666
+ /**
1667
+ * Count system logs in the archive.
1668
+ */
1669
+ countLogs(options?: {
1670
+ level?: string;
1671
+ workerId?: string;
1672
+ queue?: string;
1673
+ search?: string;
1674
+ startTime?: Date;
1675
+ endTime?: Date;
1676
+ }): Promise<number>;
1677
+ /**
1678
+ * Remove old records from the archive.
1679
+ */
1680
+ cleanup(days: number): Promise<number>;
1681
+ /**
1682
+ * Count jobs in the archive.
1683
+ */
1684
+ count(queue: string, options?: {
1685
+ status?: 'completed' | 'failed' | 'waiting' | string;
1686
+ jobId?: string;
1687
+ startTime?: Date;
1688
+ endTime?: Date;
1689
+ }): Promise<number>;
1690
+ /**
1691
+ * Setup table for SQLite.
1692
+ */
1693
+ setupTable(): Promise<void>;
1694
+ private setupJobsTable;
1695
+ private setupLogsTable;
1696
+ }
1697
+
1698
+ interface ScheduledJobConfig {
1699
+ id: string;
1700
+ cron: string;
1701
+ queue: string;
1702
+ job: SerializedJob;
1703
+ lastRun?: number;
1704
+ nextRun?: number;
1705
+ enabled: boolean;
1706
+ }
1707
+ /**
1708
+ * Scheduler
1709
+ *
1710
+ * Manages recurring (cron) jobs.
1711
+ */
1712
+ declare class Scheduler {
1713
+ private manager;
1714
+ private prefix;
1715
+ constructor(manager: QueueManager, options?: {
1716
+ prefix?: string;
1717
+ });
1718
+ private get client();
1719
+ /**
1720
+ * Register a scheduled job.
1721
+ */
1722
+ register(config: Omit<ScheduledJobConfig, 'nextRun' | 'enabled'>): Promise<void>;
1723
+ /**
1724
+ * Remove a scheduled job.
1725
+ */
1726
+ remove(id: string): Promise<void>;
1727
+ /**
1728
+ * List all scheduled jobs.
1729
+ */
1730
+ list(): Promise<ScheduledJobConfig[]>;
1731
+ /**
1732
+ * Run a scheduled job immediately (out of schedule).
1733
+ */
1734
+ runNow(id: string): Promise<void>;
1735
+ /**
1736
+ * Process due tasks (TICK).
1737
+ * This should be called periodically (e.g. every minute).
1738
+ */
1739
+ tick(): Promise<number>;
1740
+ }
1741
+
1060
1742
  /**
1061
1743
  * Class name serializer (Laravel-style).
1062
1744
  *
@@ -1129,4 +1811,4 @@ declare class JsonSerializer implements JobSerializer {
1129
1811
  deserialize(serialized: SerializedJob): Job;
1130
1812
  }
1131
1813
 
1132
- export { ClassNameSerializer, Consumer, type ConsumerOptions, DatabaseDriver, type DatabaseDriverConfig, Job, type JobSerializer, JsonSerializer, KafkaDriver, type KafkaDriverConfig, MemoryDriver, OrbitStream, type OrbitStreamOptions, type QueueConfig, type QueueConnectionConfig, type QueueDriver, QueueManager, type Queueable, RedisDriver, type RedisDriverConfig, SQSDriver, type SQSDriverConfig, type SerializedJob, type TopicOptions, Worker, type WorkerOptions };
1814
+ export { ClassNameSerializer, Consumer, type ConsumerOptions, DatabaseDriver, type DatabaseDriverConfig, Job, type JobSerializer, JsonSerializer, KafkaDriver, type KafkaDriverConfig, MemoryDriver, MySQLPersistence, OrbitStream, type OrbitStreamOptions, type PersistenceAdapter, type QueueConfig, type QueueConnectionConfig, type QueueDriver, QueueManager, type Queueable, RabbitMQDriver, type RabbitMQDriverConfig, RedisDriver, type RedisDriverConfig, SQLitePersistence, SQSDriver, type SQSDriverConfig, Scheduler, type SerializedJob, type TopicOptions, Worker, type WorkerOptions };