@gravito/stream 1.0.3 → 2.0.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/README.md +110 -5
- package/dist/index.cjs +2956 -238
- package/dist/index.d.cts +563 -123
- package/dist/index.d.ts +563 -123
- package/dist/index.js +2955 -238
- package/package.json +7 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
1
2
|
import { GravitoOrbit, PlanetCore } from '@gravito/core';
|
|
3
|
+
import { ConnectionContract } from '@gravito/atlas';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Represents a job that has been serialized for storage in a queue.
|
|
@@ -8,7 +10,7 @@ interface SerializedJob {
|
|
|
8
10
|
/** Unique job identifier */
|
|
9
11
|
id: string;
|
|
10
12
|
/** Serializer type: 'json' for plain objects or 'class' for instances */
|
|
11
|
-
type: 'json' | 'class';
|
|
13
|
+
type: 'json' | 'class' | 'msgpack';
|
|
12
14
|
/** Serialized data string */
|
|
13
15
|
data: string;
|
|
14
16
|
/** Fully qualified class name (only used for 'class' type) */
|
|
@@ -34,6 +36,24 @@ interface SerializedJob {
|
|
|
34
36
|
/** Optional priority for the job (string or numeric) */
|
|
35
37
|
priority?: string | number;
|
|
36
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Statistics for a single queue.
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
interface QueueStats {
|
|
44
|
+
/** Queue name */
|
|
45
|
+
queue: string;
|
|
46
|
+
/** Number of pending jobs */
|
|
47
|
+
size: number;
|
|
48
|
+
/** Number of delayed jobs (if supported) */
|
|
49
|
+
delayed?: number;
|
|
50
|
+
/** Number of reserved/in-flight jobs (if supported) */
|
|
51
|
+
reserved?: number;
|
|
52
|
+
/** Number of failed jobs in DLQ (if supported) */
|
|
53
|
+
failed?: number;
|
|
54
|
+
/** Additional custom metrics */
|
|
55
|
+
metrics?: Record<string, number>;
|
|
56
|
+
}
|
|
37
57
|
/**
|
|
38
58
|
* Advanced topic options for distributed queues (e.g., Kafka).
|
|
39
59
|
* @public
|
|
@@ -46,16 +66,73 @@ interface TopicOptions {
|
|
|
46
66
|
/** Additional driver-specific configurations */
|
|
47
67
|
config?: Record<string, string>;
|
|
48
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Database driver configuration.
|
|
71
|
+
* @public
|
|
72
|
+
*/
|
|
73
|
+
interface DatabaseDriverConfig$1 {
|
|
74
|
+
driver: 'database';
|
|
75
|
+
/** Database service implementation for executing queries */
|
|
76
|
+
dbService: any;
|
|
77
|
+
/** Optional table name for job storage */
|
|
78
|
+
table?: string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Redis driver configuration.
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
interface RedisDriverConfig$1 {
|
|
85
|
+
driver: 'redis';
|
|
86
|
+
/** Redis client instance (ioredis or node-redis compatible) */
|
|
87
|
+
client: any;
|
|
88
|
+
/** Optional prefix for all Redis keys */
|
|
89
|
+
prefix?: string;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Kafka driver configuration.
|
|
93
|
+
*/
|
|
94
|
+
interface KafkaDriverConfig$1 {
|
|
95
|
+
driver: 'kafka';
|
|
96
|
+
client: any;
|
|
97
|
+
consumerGroupId?: string;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* SQS driver configuration.
|
|
101
|
+
* @public
|
|
102
|
+
*/
|
|
103
|
+
interface SQSDriverConfig$1 {
|
|
104
|
+
driver: 'sqs';
|
|
105
|
+
/** Amazon SQS client instance */
|
|
106
|
+
client: any;
|
|
107
|
+
/** Optional prefix for queue URLs */
|
|
108
|
+
queueUrlPrefix?: string;
|
|
109
|
+
/** The duration (in seconds) that the received messages are hidden from subsequent retrieve requests after being retrieved by a ReceiveMessage request. */
|
|
110
|
+
visibilityTimeout?: number;
|
|
111
|
+
/** The duration (in seconds) for which the call waits for a message to arrive in the queue before returning. */
|
|
112
|
+
waitTimeSeconds?: number;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* RabbitMQ driver configuration.
|
|
116
|
+
*/
|
|
117
|
+
interface RabbitMQDriverConfig$1 {
|
|
118
|
+
driver: 'rabbitmq';
|
|
119
|
+
client: any;
|
|
120
|
+
exchange?: string;
|
|
121
|
+
exchangeType?: string;
|
|
122
|
+
}
|
|
49
123
|
/**
|
|
50
124
|
* Configuration for a specific queue connection.
|
|
51
125
|
* @public
|
|
52
126
|
*/
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
127
|
+
type QueueConnectionConfig = {
|
|
128
|
+
driver: 'memory';
|
|
129
|
+
} | DatabaseDriverConfig$1 | RedisDriverConfig$1 | KafkaDriverConfig$1 | SQSDriverConfig$1 | RabbitMQDriverConfig$1 | {
|
|
130
|
+
driver: 'nats';
|
|
57
131
|
[key: string]: unknown;
|
|
58
|
-
}
|
|
132
|
+
} | {
|
|
133
|
+
driver: string;
|
|
134
|
+
[key: string]: unknown;
|
|
135
|
+
};
|
|
59
136
|
/**
|
|
60
137
|
* Queue manager config.
|
|
61
138
|
*/
|
|
@@ -71,7 +148,18 @@ interface QueueConfig {
|
|
|
71
148
|
/**
|
|
72
149
|
* Default serializer type.
|
|
73
150
|
*/
|
|
74
|
-
defaultSerializer?: 'json' | 'class';
|
|
151
|
+
defaultSerializer?: 'json' | 'class' | 'msgpack';
|
|
152
|
+
/**
|
|
153
|
+
* Whether to enable serialization caching.
|
|
154
|
+
* If true, re-queuing the same Job instance will use the cached serialized data.
|
|
155
|
+
* @default false
|
|
156
|
+
*/
|
|
157
|
+
useSerializationCache?: boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Enable verbose debug logging for QueueManager and Consumer.
|
|
160
|
+
* @default false
|
|
161
|
+
*/
|
|
162
|
+
debug?: boolean;
|
|
75
163
|
/**
|
|
76
164
|
* Persistence configuration (SQL Archive).
|
|
77
165
|
*/
|
|
@@ -93,6 +181,16 @@ interface QueueConfig {
|
|
|
93
181
|
* @default false
|
|
94
182
|
*/
|
|
95
183
|
archiveEnqueued?: boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Buffer size for batched writes.
|
|
186
|
+
* If set, wraps the adapter in BufferedPersistence.
|
|
187
|
+
*/
|
|
188
|
+
bufferSize?: number;
|
|
189
|
+
/**
|
|
190
|
+
* Flush interval in ms for batched writes.
|
|
191
|
+
* If set, wraps the adapter in BufferedPersistence.
|
|
192
|
+
*/
|
|
193
|
+
flushInterval?: number;
|
|
96
194
|
};
|
|
97
195
|
}
|
|
98
196
|
/**
|
|
@@ -108,9 +206,6 @@ interface PersistenceAdapter {
|
|
|
108
206
|
* Find a job in the archive.
|
|
109
207
|
*/
|
|
110
208
|
find(queue: string, id: string): Promise<SerializedJob | null>;
|
|
111
|
-
/**
|
|
112
|
-
* List jobs from the archive.
|
|
113
|
-
*/
|
|
114
209
|
/**
|
|
115
210
|
* List jobs from the archive.
|
|
116
211
|
*/
|
|
@@ -122,10 +217,22 @@ interface PersistenceAdapter {
|
|
|
122
217
|
startTime?: Date;
|
|
123
218
|
endTime?: Date;
|
|
124
219
|
}): Promise<SerializedJob[]>;
|
|
220
|
+
/**
|
|
221
|
+
* Archive multiple jobs (batch write).
|
|
222
|
+
*/
|
|
223
|
+
archiveMany?(jobs: Array<{
|
|
224
|
+
queue: string;
|
|
225
|
+
job: SerializedJob;
|
|
226
|
+
status: 'completed' | 'failed' | 'waiting' | string;
|
|
227
|
+
}>): Promise<void>;
|
|
125
228
|
/**
|
|
126
229
|
* Remove old data from the archive.
|
|
127
230
|
*/
|
|
128
231
|
cleanup(days: number): Promise<number>;
|
|
232
|
+
/**
|
|
233
|
+
* Flush any buffered data.
|
|
234
|
+
*/
|
|
235
|
+
flush?(): Promise<void>;
|
|
129
236
|
/**
|
|
130
237
|
* Count jobs in the archive.
|
|
131
238
|
*/
|
|
@@ -145,6 +252,16 @@ interface PersistenceAdapter {
|
|
|
145
252
|
queue?: string;
|
|
146
253
|
timestamp: Date;
|
|
147
254
|
}): Promise<void>;
|
|
255
|
+
/**
|
|
256
|
+
* Archive multiple log messages (batch write).
|
|
257
|
+
*/
|
|
258
|
+
archiveLogMany?(logs: Array<{
|
|
259
|
+
level: string;
|
|
260
|
+
message: string;
|
|
261
|
+
workerId: string;
|
|
262
|
+
queue?: string;
|
|
263
|
+
timestamp: Date;
|
|
264
|
+
}>): Promise<void>;
|
|
148
265
|
/**
|
|
149
266
|
* List system logs from the archive.
|
|
150
267
|
*/
|
|
@@ -232,6 +349,13 @@ interface QueueDriver {
|
|
|
232
349
|
* @returns Serialized job, or `null` if the queue is empty
|
|
233
350
|
*/
|
|
234
351
|
pop(queue: string): Promise<SerializedJob | null>;
|
|
352
|
+
/**
|
|
353
|
+
* Pop a job from a queue (blocking).
|
|
354
|
+
* @param queues - Queue name or array of queue names
|
|
355
|
+
* @param timeout - Timeout in seconds
|
|
356
|
+
* @returns Serialized job, or `null` if timeout reached
|
|
357
|
+
*/
|
|
358
|
+
popBlocking?(queues: string | string[], timeout: number): Promise<SerializedJob | null>;
|
|
235
359
|
/**
|
|
236
360
|
* Mark a job as completed (used for FIFO/Group handling).
|
|
237
361
|
* @param queue - Queue name
|
|
@@ -255,6 +379,11 @@ interface QueueDriver {
|
|
|
255
379
|
* @param job - Serialized job with error info
|
|
256
380
|
*/
|
|
257
381
|
fail?(queue: string, job: SerializedJob): Promise<void>;
|
|
382
|
+
/**
|
|
383
|
+
* Get queue statistics including pending, delayed, and failed job counts.
|
|
384
|
+
* @param queue - Queue name
|
|
385
|
+
*/
|
|
386
|
+
stats?(queue: string): Promise<QueueStats>;
|
|
258
387
|
/**
|
|
259
388
|
* Push multiple jobs (optional, higher throughput).
|
|
260
389
|
* @param queue - Queue name
|
|
@@ -295,13 +424,30 @@ interface QueueDriver {
|
|
|
295
424
|
* @param workerInfo - Worker information
|
|
296
425
|
* @param prefix - Optional prefix for monitoring keys
|
|
297
426
|
*/
|
|
298
|
-
reportHeartbeat?(workerInfo:
|
|
427
|
+
reportHeartbeat?(workerInfo: {
|
|
428
|
+
id: string;
|
|
429
|
+
status: string;
|
|
430
|
+
hostname: string;
|
|
431
|
+
pid: number;
|
|
432
|
+
uptime: number;
|
|
433
|
+
last_ping: string;
|
|
434
|
+
queues: string[];
|
|
435
|
+
metrics?: Record<string, any>;
|
|
436
|
+
[key: string]: any;
|
|
437
|
+
}, prefix?: string): Promise<void>;
|
|
299
438
|
/**
|
|
300
439
|
* Publish a log message for monitoring.
|
|
301
440
|
* @param logPayload - Log payload
|
|
302
441
|
* @param prefix - Optional prefix for monitoring channels/keys
|
|
303
442
|
*/
|
|
304
|
-
publishLog?(logPayload:
|
|
443
|
+
publishLog?(logPayload: {
|
|
444
|
+
level: string;
|
|
445
|
+
message: string;
|
|
446
|
+
workerId: string;
|
|
447
|
+
jobId?: string;
|
|
448
|
+
timestamp: string;
|
|
449
|
+
[key: string]: any;
|
|
450
|
+
}, prefix?: string): Promise<void>;
|
|
305
451
|
/**
|
|
306
452
|
* Check if a queue is rate limited.
|
|
307
453
|
* @param queue - Queue name
|
|
@@ -431,6 +577,7 @@ interface Queueable {
|
|
|
431
577
|
* .onQueue('emails')
|
|
432
578
|
* .delay(60)
|
|
433
579
|
* ```
|
|
580
|
+
* @public
|
|
434
581
|
*/
|
|
435
582
|
declare abstract class Job implements Queueable {
|
|
436
583
|
/**
|
|
@@ -519,6 +666,78 @@ declare abstract class Job implements Queueable {
|
|
|
519
666
|
failed(_error: Error): Promise<void>;
|
|
520
667
|
}
|
|
521
668
|
|
|
669
|
+
/**
|
|
670
|
+
* Configuration for a recurring scheduled job.
|
|
671
|
+
*
|
|
672
|
+
* @public
|
|
673
|
+
* @since 3.0.0
|
|
674
|
+
*/
|
|
675
|
+
interface ScheduledJobConfig {
|
|
676
|
+
/** Unique identifier for the scheduled task. */
|
|
677
|
+
id: string;
|
|
678
|
+
/** Cron expression defining the schedule (e.g., '* * * * *'). */
|
|
679
|
+
cron: string;
|
|
680
|
+
/** The target queue name where the job should be pushed. */
|
|
681
|
+
queue: string;
|
|
682
|
+
/** The serialized job data. */
|
|
683
|
+
job: SerializedJob;
|
|
684
|
+
/** Timestamp of the last successful execution in milliseconds. */
|
|
685
|
+
lastRun?: number;
|
|
686
|
+
/** Timestamp of the next scheduled execution in milliseconds. */
|
|
687
|
+
nextRun?: number;
|
|
688
|
+
/** Whether the scheduled job is active. */
|
|
689
|
+
enabled: boolean;
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* Scheduler manages recurring (cron) jobs in Gravito.
|
|
693
|
+
*
|
|
694
|
+
* It uses Redis to store schedule metadata and coordinates distributed
|
|
695
|
+
* execution using locks to ensure jobs are triggered exactly once per interval.
|
|
696
|
+
*
|
|
697
|
+
* @example
|
|
698
|
+
* ```typescript
|
|
699
|
+
* const scheduler = new Scheduler(queueManager);
|
|
700
|
+
* await scheduler.register({
|
|
701
|
+
* id: 'daily-cleanup',
|
|
702
|
+
* cron: '0 0 * * *',
|
|
703
|
+
* queue: 'default',
|
|
704
|
+
* job: myJob.serialize()
|
|
705
|
+
* });
|
|
706
|
+
* ```
|
|
707
|
+
*
|
|
708
|
+
* @public
|
|
709
|
+
* @since 3.0.0
|
|
710
|
+
*/
|
|
711
|
+
declare class Scheduler {
|
|
712
|
+
private manager;
|
|
713
|
+
private prefix;
|
|
714
|
+
constructor(manager: QueueManager, options?: {
|
|
715
|
+
prefix?: string;
|
|
716
|
+
});
|
|
717
|
+
private get client();
|
|
718
|
+
/**
|
|
719
|
+
* Register a scheduled job.
|
|
720
|
+
*/
|
|
721
|
+
register(config: Omit<ScheduledJobConfig, 'nextRun' | 'enabled'>): Promise<void>;
|
|
722
|
+
/**
|
|
723
|
+
* Remove a scheduled job.
|
|
724
|
+
*/
|
|
725
|
+
remove(id: string): Promise<void>;
|
|
726
|
+
/**
|
|
727
|
+
* List all scheduled jobs.
|
|
728
|
+
*/
|
|
729
|
+
list(): Promise<ScheduledJobConfig[]>;
|
|
730
|
+
/**
|
|
731
|
+
* Run a scheduled job immediately (out of schedule).
|
|
732
|
+
*/
|
|
733
|
+
runNow(id: string): Promise<void>;
|
|
734
|
+
/**
|
|
735
|
+
* Process due tasks (TICK).
|
|
736
|
+
* This should be called periodically (e.g. every minute).
|
|
737
|
+
*/
|
|
738
|
+
tick(): Promise<number>;
|
|
739
|
+
}
|
|
740
|
+
|
|
522
741
|
/**
|
|
523
742
|
* Job serializer interface.
|
|
524
743
|
*
|
|
@@ -579,13 +798,18 @@ declare class QueueManager {
|
|
|
579
798
|
private defaultSerializer;
|
|
580
799
|
private persistence?;
|
|
581
800
|
private scheduler?;
|
|
801
|
+
private debug;
|
|
582
802
|
constructor(config?: QueueConfig);
|
|
803
|
+
/**
|
|
804
|
+
* Log debug message.
|
|
805
|
+
*/
|
|
806
|
+
private log;
|
|
583
807
|
/**
|
|
584
808
|
* Register a connection.
|
|
585
809
|
* @param name - Connection name
|
|
586
810
|
* @param config - Connection config
|
|
587
811
|
*/
|
|
588
|
-
registerConnection(name: string, config:
|
|
812
|
+
registerConnection(name: string, config: QueueConnectionConfig): void;
|
|
589
813
|
/**
|
|
590
814
|
* Get a driver for a connection.
|
|
591
815
|
* @param connection - Connection name
|
|
@@ -627,13 +851,17 @@ declare class QueueManager {
|
|
|
627
851
|
*
|
|
628
852
|
* @template T - The type of the jobs.
|
|
629
853
|
* @param jobs - Array of job instances.
|
|
854
|
+
* @param options - Bulk push options.
|
|
630
855
|
*
|
|
631
856
|
* @example
|
|
632
857
|
* ```typescript
|
|
633
|
-
* await manager.pushMany(
|
|
858
|
+
* await manager.pushMany(jobs, { batchSize: 500, concurrency: 2 });
|
|
634
859
|
* ```
|
|
635
860
|
*/
|
|
636
|
-
pushMany<T extends Job & Queueable>(jobs: T[]
|
|
861
|
+
pushMany<T extends Job & Queueable>(jobs: T[], options?: {
|
|
862
|
+
batchSize?: number;
|
|
863
|
+
concurrency?: number;
|
|
864
|
+
}): Promise<void>;
|
|
637
865
|
/**
|
|
638
866
|
* Pop a job from the queue.
|
|
639
867
|
*
|
|
@@ -648,6 +876,15 @@ declare class QueueManager {
|
|
|
648
876
|
* ```
|
|
649
877
|
*/
|
|
650
878
|
pop(queue?: string, connection?: string): Promise<Job | null>;
|
|
879
|
+
/**
|
|
880
|
+
* Pop multiple jobs from the queue.
|
|
881
|
+
*
|
|
882
|
+
* @param queue - Queue name (default: 'default').
|
|
883
|
+
* @param count - Number of jobs to pop (default: 10).
|
|
884
|
+
* @param connection - Connection name (optional).
|
|
885
|
+
* @returns Array of Job instances.
|
|
886
|
+
*/
|
|
887
|
+
popMany(queue?: string, count?: number, connection?: string): Promise<Job[]>;
|
|
651
888
|
/**
|
|
652
889
|
* Get queue size.
|
|
653
890
|
*
|
|
@@ -656,6 +893,14 @@ declare class QueueManager {
|
|
|
656
893
|
* @returns Number of jobs in the queue.
|
|
657
894
|
*/
|
|
658
895
|
size(queue?: string, connection?: string): Promise<number>;
|
|
896
|
+
/**
|
|
897
|
+
* Pop a job from the queue (blocking).
|
|
898
|
+
*
|
|
899
|
+
* @param queue - Queue name (default: 'default').
|
|
900
|
+
* @param timeout - Timeout in seconds (default: 0, wait forever).
|
|
901
|
+
* @param connection - Connection name (optional).
|
|
902
|
+
*/
|
|
903
|
+
popBlocking(queues?: string | string[], timeout?: number, connection?: string): Promise<Job | null>;
|
|
659
904
|
/**
|
|
660
905
|
* Clear all jobs from a queue.
|
|
661
906
|
*
|
|
@@ -663,6 +908,14 @@ declare class QueueManager {
|
|
|
663
908
|
* @param connection - Connection name (optional).
|
|
664
909
|
*/
|
|
665
910
|
clear(queue?: string, connection?: string): Promise<void>;
|
|
911
|
+
/**
|
|
912
|
+
* Get queue statistics including size, delayed, and failed job counts.
|
|
913
|
+
*
|
|
914
|
+
* @param queue - Queue name (default: 'default').
|
|
915
|
+
* @param connection - Connection name (optional).
|
|
916
|
+
* @returns Queue statistics object.
|
|
917
|
+
*/
|
|
918
|
+
stats(queue?: string, connection?: string): Promise<QueueStats>;
|
|
666
919
|
/**
|
|
667
920
|
* Mark a job as completed.
|
|
668
921
|
* @param job - Job instance
|
|
@@ -677,11 +930,11 @@ declare class QueueManager {
|
|
|
677
930
|
/**
|
|
678
931
|
* Get the persistence adapter if configured.
|
|
679
932
|
*/
|
|
680
|
-
getPersistence():
|
|
933
|
+
getPersistence(): PersistenceAdapter | undefined;
|
|
681
934
|
/**
|
|
682
935
|
* Get the scheduler if configured.
|
|
683
936
|
*/
|
|
684
|
-
getScheduler():
|
|
937
|
+
getScheduler(): Scheduler;
|
|
685
938
|
/**
|
|
686
939
|
* Get failed jobs from DLQ (if driver supports it).
|
|
687
940
|
*/
|
|
@@ -778,7 +1031,7 @@ interface ConsumerOptions {
|
|
|
778
1031
|
/**
|
|
779
1032
|
* Extra info to report with heartbeat.
|
|
780
1033
|
*/
|
|
781
|
-
extraInfo?: Record<string,
|
|
1034
|
+
extraInfo?: Record<string, unknown>;
|
|
782
1035
|
/**
|
|
783
1036
|
* Prefix for monitoring keys/channels.
|
|
784
1037
|
*/
|
|
@@ -792,6 +1045,54 @@ interface ConsumerOptions {
|
|
|
792
1045
|
max: number;
|
|
793
1046
|
duration: number;
|
|
794
1047
|
}>;
|
|
1048
|
+
/**
|
|
1049
|
+
* Max concurrent jobs to process. Default: 1.
|
|
1050
|
+
*/
|
|
1051
|
+
concurrency?: number;
|
|
1052
|
+
/**
|
|
1053
|
+
* Whether to process jobs with the same groupId sequentially.
|
|
1054
|
+
* If true, jobs with the same groupId will never run concurrently,
|
|
1055
|
+
* regardless of the global concurrency setting.
|
|
1056
|
+
* @default true
|
|
1057
|
+
*/
|
|
1058
|
+
groupJobsSequential?: boolean;
|
|
1059
|
+
/**
|
|
1060
|
+
* Minimum polling interval in ms (for adaptive polling).
|
|
1061
|
+
* @default 100
|
|
1062
|
+
*/
|
|
1063
|
+
minPollInterval?: number;
|
|
1064
|
+
/**
|
|
1065
|
+
* Maximum polling interval in ms (for adaptive polling).
|
|
1066
|
+
* @default 5000
|
|
1067
|
+
*/
|
|
1068
|
+
maxPollInterval?: number;
|
|
1069
|
+
/**
|
|
1070
|
+
* Backoff multiplier for adaptive polling.
|
|
1071
|
+
* @default 1.5
|
|
1072
|
+
*/
|
|
1073
|
+
backoffMultiplier?: number;
|
|
1074
|
+
/**
|
|
1075
|
+
* Batch size for consuming jobs.
|
|
1076
|
+
* If > 1, tries to fetch multiple jobs at once.
|
|
1077
|
+
* @default 1
|
|
1078
|
+
*/
|
|
1079
|
+
batchSize?: number;
|
|
1080
|
+
/**
|
|
1081
|
+
* Whether to use blocking pop (BLPOP/long-polling) if supported by driver.
|
|
1082
|
+
* Only applies when batchSize is 1.
|
|
1083
|
+
* @default true
|
|
1084
|
+
*/
|
|
1085
|
+
useBlocking?: boolean;
|
|
1086
|
+
/**
|
|
1087
|
+
* Timeout in seconds for blocking pop.
|
|
1088
|
+
* @default 5
|
|
1089
|
+
*/
|
|
1090
|
+
blockingTimeout?: number;
|
|
1091
|
+
/**
|
|
1092
|
+
* Enable verbose debug logging.
|
|
1093
|
+
* @default false
|
|
1094
|
+
*/
|
|
1095
|
+
debug?: boolean;
|
|
795
1096
|
}
|
|
796
1097
|
/**
|
|
797
1098
|
* Consumer
|
|
@@ -812,20 +1113,40 @@ interface ConsumerOptions {
|
|
|
812
1113
|
* // Standalone mode (CLI)
|
|
813
1114
|
* // Start via CLI tooling with graceful shutdown
|
|
814
1115
|
* ```
|
|
1116
|
+
*
|
|
1117
|
+
* @emits job:started - When a job begins processing. Payload: { job: Job, queue: string }
|
|
1118
|
+
* @emits job:processed - When a job completes successfully. Payload: { job: Job, duration: number, queue: string }
|
|
1119
|
+
* @emits job:failed - When a job fails an attempt. Payload: { job: Job, error: Error, duration: number, queue: string }
|
|
1120
|
+
* @emits job:retried - When a job is scheduled for a retry. Payload: { job: Job, attempt: number, delay: number }
|
|
1121
|
+
* @emits job:failed_permanently - When a job fails all attempts and is moved to DLQ. Payload: { job: Job, error: Error }
|
|
815
1122
|
*/
|
|
816
|
-
declare class Consumer {
|
|
1123
|
+
declare class Consumer extends EventEmitter {
|
|
817
1124
|
private queueManager;
|
|
818
1125
|
private options;
|
|
819
1126
|
private running;
|
|
820
1127
|
private stopRequested;
|
|
821
1128
|
private workerId;
|
|
822
1129
|
private heartbeatTimer;
|
|
1130
|
+
private groupLimiters;
|
|
1131
|
+
private stats;
|
|
823
1132
|
constructor(queueManager: QueueManager, options: ConsumerOptions);
|
|
824
1133
|
private get connectionName();
|
|
1134
|
+
/**
|
|
1135
|
+
* Log debug message.
|
|
1136
|
+
*/
|
|
1137
|
+
private log;
|
|
825
1138
|
/**
|
|
826
1139
|
* Start the consumer loop.
|
|
827
1140
|
*/
|
|
828
1141
|
start(): Promise<void>;
|
|
1142
|
+
/**
|
|
1143
|
+
* Run a job with concurrency controls.
|
|
1144
|
+
*/
|
|
1145
|
+
private runJob;
|
|
1146
|
+
/**
|
|
1147
|
+
* Handle a single job.
|
|
1148
|
+
*/
|
|
1149
|
+
private handleJob;
|
|
829
1150
|
private startHeartbeat;
|
|
830
1151
|
private stopHeartbeat;
|
|
831
1152
|
private publishLog;
|
|
@@ -837,6 +1158,19 @@ declare class Consumer {
|
|
|
837
1158
|
* Check whether the consumer is running.
|
|
838
1159
|
*/
|
|
839
1160
|
isRunning(): boolean;
|
|
1161
|
+
/**
|
|
1162
|
+
* Get current consumer statistics.
|
|
1163
|
+
*/
|
|
1164
|
+
getStats(): {
|
|
1165
|
+
processed: number;
|
|
1166
|
+
failed: number;
|
|
1167
|
+
retried: number;
|
|
1168
|
+
active: number;
|
|
1169
|
+
};
|
|
1170
|
+
/**
|
|
1171
|
+
* Reset statistics counters.
|
|
1172
|
+
*/
|
|
1173
|
+
resetStats(): void;
|
|
840
1174
|
}
|
|
841
1175
|
|
|
842
1176
|
/**
|
|
@@ -899,6 +1233,14 @@ declare class DatabaseDriver implements QueueDriver {
|
|
|
899
1233
|
* Pop a job from the queue (FIFO, with delay support).
|
|
900
1234
|
*/
|
|
901
1235
|
pop(queue: string): Promise<SerializedJob | null>;
|
|
1236
|
+
/**
|
|
1237
|
+
* Pop multiple jobs from the queue.
|
|
1238
|
+
*/
|
|
1239
|
+
popMany(queue: string, count: number): Promise<SerializedJob[]>;
|
|
1240
|
+
/**
|
|
1241
|
+
* Get queue statistics.
|
|
1242
|
+
*/
|
|
1243
|
+
stats(queue: string): Promise<QueueStats>;
|
|
902
1244
|
/**
|
|
903
1245
|
* Get queue size.
|
|
904
1246
|
*/
|
|
@@ -907,8 +1249,14 @@ declare class DatabaseDriver implements QueueDriver {
|
|
|
907
1249
|
* Clear a queue.
|
|
908
1250
|
*/
|
|
909
1251
|
clear(queue: string): Promise<void>;
|
|
1252
|
+
/**
|
|
1253
|
+
* Pop a job from the queue (blocking).
|
|
1254
|
+
* Simple polling fallback for databases.
|
|
1255
|
+
*/
|
|
1256
|
+
popBlocking(queue: string, timeout: number): Promise<SerializedJob | null>;
|
|
910
1257
|
/**
|
|
911
1258
|
* Push multiple jobs.
|
|
1259
|
+
* Optimizes by using a single multi-row insert if possible.
|
|
912
1260
|
*/
|
|
913
1261
|
pushMany(queue: string, jobs: SerializedJob[]): Promise<void>;
|
|
914
1262
|
/**
|
|
@@ -1053,6 +1401,13 @@ declare class KafkaDriver implements QueueDriver {
|
|
|
1053
1401
|
subscribe(queue: string, callback: (job: SerializedJob) => Promise<void>): Promise<void>;
|
|
1054
1402
|
}
|
|
1055
1403
|
|
|
1404
|
+
interface MemoryDriverConfig {
|
|
1405
|
+
/**
|
|
1406
|
+
* Maximum number of jobs per queue.
|
|
1407
|
+
* @default Infinity
|
|
1408
|
+
*/
|
|
1409
|
+
maxSize?: number;
|
|
1410
|
+
}
|
|
1056
1411
|
/**
|
|
1057
1412
|
* Memory Driver
|
|
1058
1413
|
*
|
|
@@ -1063,13 +1418,15 @@ declare class KafkaDriver implements QueueDriver {
|
|
|
1063
1418
|
*
|
|
1064
1419
|
* @example
|
|
1065
1420
|
* ```typescript
|
|
1066
|
-
* const driver = new MemoryDriver()
|
|
1421
|
+
* const driver = new MemoryDriver({ maxSize: 1000 })
|
|
1067
1422
|
* await driver.push('default', serializedJob)
|
|
1068
1423
|
* const job = await driver.pop('default')
|
|
1069
1424
|
* ```
|
|
1070
1425
|
*/
|
|
1071
1426
|
declare class MemoryDriver implements QueueDriver {
|
|
1072
1427
|
private queues;
|
|
1428
|
+
private maxSize;
|
|
1429
|
+
constructor(config?: MemoryDriverConfig);
|
|
1073
1430
|
/**
|
|
1074
1431
|
* Push a job to a queue.
|
|
1075
1432
|
*/
|
|
@@ -1086,6 +1443,14 @@ declare class MemoryDriver implements QueueDriver {
|
|
|
1086
1443
|
* Clear a queue.
|
|
1087
1444
|
*/
|
|
1088
1445
|
clear(queue: string): Promise<void>;
|
|
1446
|
+
/**
|
|
1447
|
+
* Mark a job as permanently failed.
|
|
1448
|
+
*/
|
|
1449
|
+
fail(queue: string, job: SerializedJob): Promise<void>;
|
|
1450
|
+
/**
|
|
1451
|
+
* Get queue statistics.
|
|
1452
|
+
*/
|
|
1453
|
+
stats(queue: string): Promise<QueueStats>;
|
|
1089
1454
|
/**
|
|
1090
1455
|
* Push multiple jobs.
|
|
1091
1456
|
*/
|
|
@@ -1154,6 +1519,11 @@ declare class RabbitMQDriver implements QueueDriver {
|
|
|
1154
1519
|
* Pop a job (get).
|
|
1155
1520
|
*/
|
|
1156
1521
|
pop(queue: string): Promise<SerializedJob | null>;
|
|
1522
|
+
/**
|
|
1523
|
+
* Pop multiple jobs.
|
|
1524
|
+
* Uses channel.get() in a loop (no native batch get in AMQP).
|
|
1525
|
+
*/
|
|
1526
|
+
popMany(queue: string, count: number): Promise<SerializedJob[]>;
|
|
1157
1527
|
/**
|
|
1158
1528
|
* Acknowledge a message.
|
|
1159
1529
|
*/
|
|
@@ -1171,6 +1541,7 @@ declare class RabbitMQDriver implements QueueDriver {
|
|
|
1171
1541
|
*/
|
|
1172
1542
|
subscribe(queue: string, callback: (job: SerializedJob) => Promise<void>, options?: {
|
|
1173
1543
|
autoAck?: boolean;
|
|
1544
|
+
prefetch?: number;
|
|
1174
1545
|
}): Promise<void>;
|
|
1175
1546
|
/**
|
|
1176
1547
|
* Get queue size.
|
|
@@ -1182,6 +1553,34 @@ declare class RabbitMQDriver implements QueueDriver {
|
|
|
1182
1553
|
clear(queue: string): Promise<void>;
|
|
1183
1554
|
}
|
|
1184
1555
|
|
|
1556
|
+
/**
|
|
1557
|
+
* Interface for Redis clients (compatible with ioredis and node-redis).
|
|
1558
|
+
*/
|
|
1559
|
+
interface RedisClient {
|
|
1560
|
+
lpush(key: string, ...values: string[]): Promise<number>;
|
|
1561
|
+
rpop(key: string, count?: number): Promise<string | string[] | null>;
|
|
1562
|
+
llen(key: string): Promise<number>;
|
|
1563
|
+
del(key: string, ...keys: string[]): Promise<number>;
|
|
1564
|
+
lpushx?(key: string, ...values: string[]): Promise<number>;
|
|
1565
|
+
rpoplpush?(src: string, dst: string): Promise<string | null>;
|
|
1566
|
+
zadd?(key: string, score: number, member: string): Promise<number>;
|
|
1567
|
+
zrange?(key: string, start: number, end: number, ...args: string[]): Promise<string[]>;
|
|
1568
|
+
zrem?(key: string, ...members: string[]): Promise<number>;
|
|
1569
|
+
get?(key: string): Promise<string | null>;
|
|
1570
|
+
set?(key: string, value: string, ...args: any[]): Promise<'OK' | null>;
|
|
1571
|
+
ltrim?(key: string, start: number, stop: number): Promise<'OK'>;
|
|
1572
|
+
lrange?(key: string, start: number, stop: number): Promise<string[]>;
|
|
1573
|
+
publish?(channel: string, message: string): Promise<number>;
|
|
1574
|
+
pipeline?(): any;
|
|
1575
|
+
defineCommand?(name: string, options: {
|
|
1576
|
+
numberOfKeys: number;
|
|
1577
|
+
lua: string;
|
|
1578
|
+
}): void;
|
|
1579
|
+
incr?(key: string): Promise<number>;
|
|
1580
|
+
expire?(key: string, seconds: number): Promise<number>;
|
|
1581
|
+
eval(script: string, numKeys: number, ...args: (string | number)[]): Promise<any>;
|
|
1582
|
+
[key: string]: any;
|
|
1583
|
+
}
|
|
1185
1584
|
/**
|
|
1186
1585
|
* Redis driver configuration.
|
|
1187
1586
|
*/
|
|
@@ -1189,15 +1588,7 @@ interface RedisDriverConfig {
|
|
|
1189
1588
|
/**
|
|
1190
1589
|
* Redis client instance (ioredis or node-redis).
|
|
1191
1590
|
*/
|
|
1192
|
-
client:
|
|
1193
|
-
lpush: (key: string, ...values: string[]) => Promise<number>;
|
|
1194
|
-
rpop: (key: string) => Promise<string | null>;
|
|
1195
|
-
llen: (key: string) => Promise<number>;
|
|
1196
|
-
del: (key: string) => Promise<number>;
|
|
1197
|
-
lpushx?: (key: string, ...values: string[]) => Promise<number>;
|
|
1198
|
-
rpoplpush?: (src: string, dst: string) => Promise<string | null>;
|
|
1199
|
-
[key: string]: unknown;
|
|
1200
|
-
};
|
|
1591
|
+
client: RedisClient;
|
|
1201
1592
|
/**
|
|
1202
1593
|
* Key prefix (default: `queue:`).
|
|
1203
1594
|
*/
|
|
@@ -1227,6 +1618,7 @@ declare class RedisDriver implements QueueDriver {
|
|
|
1227
1618
|
private client;
|
|
1228
1619
|
private static PUSH_SCRIPT;
|
|
1229
1620
|
private static COMPLETE_SCRIPT;
|
|
1621
|
+
private static POP_MANY_SCRIPT;
|
|
1230
1622
|
constructor(config: RedisDriverConfig);
|
|
1231
1623
|
/**
|
|
1232
1624
|
* Get full Redis key for a queue.
|
|
@@ -1241,10 +1633,19 @@ declare class RedisDriver implements QueueDriver {
|
|
|
1241
1633
|
*/
|
|
1242
1634
|
complete(queue: string, job: SerializedJob): Promise<void>;
|
|
1243
1635
|
/**
|
|
1244
|
-
* Pop a job (
|
|
1245
|
-
*
|
|
1636
|
+
* Pop a job from a queue (non-blocking).
|
|
1637
|
+
* Optimized with Lua script for atomic priority polling.
|
|
1246
1638
|
*/
|
|
1247
1639
|
pop(queue: string): Promise<SerializedJob | null>;
|
|
1640
|
+
/**
|
|
1641
|
+
* Manual fallback for pop if Lua fails.
|
|
1642
|
+
*/
|
|
1643
|
+
private popManualFallback;
|
|
1644
|
+
/**
|
|
1645
|
+
* Pop a job from the queue (blocking).
|
|
1646
|
+
* Uses BRPOP for efficiency. Supports multiple queues and priorities.
|
|
1647
|
+
*/
|
|
1648
|
+
popBlocking(queues: string | string[], timeout: number): Promise<SerializedJob | null>;
|
|
1248
1649
|
/**
|
|
1249
1650
|
* Parse Redis payload.
|
|
1250
1651
|
*/
|
|
@@ -1261,12 +1662,18 @@ declare class RedisDriver implements QueueDriver {
|
|
|
1261
1662
|
* Clear a queue.
|
|
1262
1663
|
*/
|
|
1263
1664
|
clear(queue: string): Promise<void>;
|
|
1665
|
+
/**
|
|
1666
|
+
* Get queue statistics.
|
|
1667
|
+
* Optimized with Redis Pipeline to fetch all priorities and DLQ stats in one trip.
|
|
1668
|
+
*/
|
|
1669
|
+
stats(queue: string): Promise<QueueStats>;
|
|
1264
1670
|
/**
|
|
1265
1671
|
* Push multiple jobs.
|
|
1266
1672
|
*/
|
|
1267
1673
|
pushMany(queue: string, jobs: SerializedJob[]): Promise<void>;
|
|
1268
1674
|
/**
|
|
1269
1675
|
* Pop multiple jobs.
|
|
1676
|
+
* Atomic operation across multiple priority levels.
|
|
1270
1677
|
*/
|
|
1271
1678
|
popMany(queue: string, count: number): Promise<SerializedJob[]>;
|
|
1272
1679
|
/**
|
|
@@ -1373,6 +1780,11 @@ declare class SQSDriver implements QueueDriver {
|
|
|
1373
1780
|
* Pop a job (long polling).
|
|
1374
1781
|
*/
|
|
1375
1782
|
pop(queue: string): Promise<SerializedJob | null>;
|
|
1783
|
+
/**
|
|
1784
|
+
* Pop multiple jobs.
|
|
1785
|
+
* Leverages SQS MaxNumberOfMessages (up to 10).
|
|
1786
|
+
*/
|
|
1787
|
+
popMany(queue: string, count: number): Promise<SerializedJob[]>;
|
|
1376
1788
|
/**
|
|
1377
1789
|
* Get queue size (approximate).
|
|
1378
1790
|
*/
|
|
@@ -1465,6 +1877,79 @@ declare module '@gravito/core' {
|
|
|
1465
1877
|
}
|
|
1466
1878
|
}
|
|
1467
1879
|
|
|
1880
|
+
/**
|
|
1881
|
+
* Buffered Persistence Wrapper.
|
|
1882
|
+
* Wraps any PersistenceAdapter to add buffering and batch writing capabilities.
|
|
1883
|
+
*/
|
|
1884
|
+
declare class BufferedPersistence implements PersistenceAdapter {
|
|
1885
|
+
private adapter;
|
|
1886
|
+
private jobBuffer;
|
|
1887
|
+
private logBuffer;
|
|
1888
|
+
private flushTimer;
|
|
1889
|
+
private maxBufferSize;
|
|
1890
|
+
private flushInterval;
|
|
1891
|
+
constructor(adapter: PersistenceAdapter, options?: {
|
|
1892
|
+
maxBufferSize?: number;
|
|
1893
|
+
flushInterval?: number;
|
|
1894
|
+
});
|
|
1895
|
+
archive(queue: string, job: SerializedJob, status: 'completed' | 'failed' | 'waiting' | string): Promise<void>;
|
|
1896
|
+
find(queue: string, id: string): Promise<SerializedJob | null>;
|
|
1897
|
+
list(queue: string, options?: {
|
|
1898
|
+
limit?: number;
|
|
1899
|
+
offset?: number;
|
|
1900
|
+
status?: 'completed' | 'failed' | 'waiting' | string;
|
|
1901
|
+
jobId?: string;
|
|
1902
|
+
startTime?: Date;
|
|
1903
|
+
endTime?: Date;
|
|
1904
|
+
}): Promise<SerializedJob[]>;
|
|
1905
|
+
archiveMany(jobs: Array<{
|
|
1906
|
+
queue: string;
|
|
1907
|
+
job: SerializedJob;
|
|
1908
|
+
status: 'completed' | 'failed' | 'waiting' | string;
|
|
1909
|
+
}>): Promise<void>;
|
|
1910
|
+
cleanup(days: number): Promise<number>;
|
|
1911
|
+
flush(): Promise<void>;
|
|
1912
|
+
count(queue: string, options?: {
|
|
1913
|
+
status?: 'completed' | 'failed' | 'waiting' | string;
|
|
1914
|
+
jobId?: string;
|
|
1915
|
+
startTime?: Date;
|
|
1916
|
+
endTime?: Date;
|
|
1917
|
+
}): Promise<number>;
|
|
1918
|
+
archiveLog(log: {
|
|
1919
|
+
level: string;
|
|
1920
|
+
message: string;
|
|
1921
|
+
workerId: string;
|
|
1922
|
+
queue?: string;
|
|
1923
|
+
timestamp: Date;
|
|
1924
|
+
}): Promise<void>;
|
|
1925
|
+
archiveLogMany(logs: Array<{
|
|
1926
|
+
level: string;
|
|
1927
|
+
message: string;
|
|
1928
|
+
workerId: string;
|
|
1929
|
+
queue?: string;
|
|
1930
|
+
timestamp: Date;
|
|
1931
|
+
}>): Promise<void>;
|
|
1932
|
+
listLogs(options?: {
|
|
1933
|
+
limit?: number;
|
|
1934
|
+
offset?: number;
|
|
1935
|
+
level?: string;
|
|
1936
|
+
workerId?: string;
|
|
1937
|
+
queue?: string;
|
|
1938
|
+
search?: string;
|
|
1939
|
+
startTime?: Date;
|
|
1940
|
+
endTime?: Date;
|
|
1941
|
+
}): Promise<any[]>;
|
|
1942
|
+
countLogs(options?: {
|
|
1943
|
+
level?: string;
|
|
1944
|
+
workerId?: string;
|
|
1945
|
+
queue?: string;
|
|
1946
|
+
search?: string;
|
|
1947
|
+
startTime?: Date;
|
|
1948
|
+
endTime?: Date;
|
|
1949
|
+
}): Promise<number>;
|
|
1950
|
+
private ensureFlushTimer;
|
|
1951
|
+
}
|
|
1952
|
+
|
|
1468
1953
|
/**
|
|
1469
1954
|
* MySQL Persistence Adapter.
|
|
1470
1955
|
* Archives jobs into a MySQL table for long-term auditing.
|
|
@@ -1476,15 +1961,20 @@ declare class MySQLPersistence implements PersistenceAdapter {
|
|
|
1476
1961
|
/**
|
|
1477
1962
|
* @param db - An Atlas DB instance or compatible QueryBuilder.
|
|
1478
1963
|
* @param table - The name of the table to store archived jobs.
|
|
1964
|
+
* @param logsTable - The name of the table to store system logs.
|
|
1965
|
+
* @param options - Buffering options (Deprecated: Use BufferedPersistence wrapper instead).
|
|
1479
1966
|
*/
|
|
1480
|
-
constructor(db:
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1967
|
+
constructor(db: ConnectionContract, table?: string, logsTable?: string, _options?: {
|
|
1968
|
+
maxBufferSize?: number;
|
|
1969
|
+
flushInterval?: number;
|
|
1970
|
+
});
|
|
1484
1971
|
archive(queue: string, job: SerializedJob, status: 'completed' | 'failed' | 'waiting' | string): Promise<void>;
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1972
|
+
archiveMany(jobs: Array<{
|
|
1973
|
+
queue: string;
|
|
1974
|
+
job: SerializedJob;
|
|
1975
|
+
status: 'completed' | 'failed' | 'waiting' | string;
|
|
1976
|
+
}>): Promise<void>;
|
|
1977
|
+
flush(): Promise<void>;
|
|
1488
1978
|
find(queue: string, id: string): Promise<SerializedJob | null>;
|
|
1489
1979
|
/**
|
|
1490
1980
|
* List jobs from the archive.
|
|
@@ -1506,7 +1996,7 @@ declare class MySQLPersistence implements PersistenceAdapter {
|
|
|
1506
1996
|
queue?: string;
|
|
1507
1997
|
}): Promise<SerializedJob[]>;
|
|
1508
1998
|
/**
|
|
1509
|
-
* Archive a system log message.
|
|
1999
|
+
* Archive a system log message (buffered).
|
|
1510
2000
|
*/
|
|
1511
2001
|
archiveLog(log: {
|
|
1512
2002
|
level: string;
|
|
@@ -1515,6 +2005,16 @@ declare class MySQLPersistence implements PersistenceAdapter {
|
|
|
1515
2005
|
queue?: string;
|
|
1516
2006
|
timestamp: Date;
|
|
1517
2007
|
}): Promise<void>;
|
|
2008
|
+
/**
|
|
2009
|
+
* Archive multiple log messages (direct batch write).
|
|
2010
|
+
*/
|
|
2011
|
+
archiveLogMany(logs: Array<{
|
|
2012
|
+
level: string;
|
|
2013
|
+
message: string;
|
|
2014
|
+
workerId: string;
|
|
2015
|
+
queue?: string;
|
|
2016
|
+
timestamp: Date;
|
|
2017
|
+
}>): Promise<void>;
|
|
1518
2018
|
/**
|
|
1519
2019
|
* List system logs from the archive.
|
|
1520
2020
|
*/
|
|
@@ -1571,15 +2071,20 @@ declare class SQLitePersistence implements PersistenceAdapter {
|
|
|
1571
2071
|
/**
|
|
1572
2072
|
* @param db - An Atlas DB instance (SQLite driver).
|
|
1573
2073
|
* @param table - The name of the table to store archived jobs.
|
|
2074
|
+
* @param logsTable - The name of the table to store system logs.
|
|
2075
|
+
* @param options - Buffering options (Deprecated: Use BufferedPersistence wrapper instead).
|
|
1574
2076
|
*/
|
|
1575
|
-
constructor(db:
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
2077
|
+
constructor(db: ConnectionContract, table?: string, logsTable?: string, _options?: {
|
|
2078
|
+
maxBufferSize?: number;
|
|
2079
|
+
flushInterval?: number;
|
|
2080
|
+
});
|
|
1579
2081
|
archive(queue: string, job: SerializedJob, status: 'completed' | 'failed' | 'waiting' | string): Promise<void>;
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
2082
|
+
archiveMany(jobs: Array<{
|
|
2083
|
+
queue: string;
|
|
2084
|
+
job: SerializedJob;
|
|
2085
|
+
status: 'completed' | 'failed' | 'waiting' | string;
|
|
2086
|
+
}>): Promise<void>;
|
|
2087
|
+
flush(): Promise<void>;
|
|
1583
2088
|
find(queue: string, id: string): Promise<SerializedJob | null>;
|
|
1584
2089
|
/**
|
|
1585
2090
|
* List jobs from the archive.
|
|
@@ -1601,7 +2106,7 @@ declare class SQLitePersistence implements PersistenceAdapter {
|
|
|
1601
2106
|
queue?: string;
|
|
1602
2107
|
}): Promise<SerializedJob[]>;
|
|
1603
2108
|
/**
|
|
1604
|
-
* Archive a system log message.
|
|
2109
|
+
* Archive a system log message (buffered).
|
|
1605
2110
|
*/
|
|
1606
2111
|
archiveLog(log: {
|
|
1607
2112
|
level: string;
|
|
@@ -1610,6 +2115,16 @@ declare class SQLitePersistence implements PersistenceAdapter {
|
|
|
1610
2115
|
queue?: string;
|
|
1611
2116
|
timestamp: Date;
|
|
1612
2117
|
}): Promise<void>;
|
|
2118
|
+
/**
|
|
2119
|
+
* Archive multiple log messages (direct batch write).
|
|
2120
|
+
*/
|
|
2121
|
+
archiveLogMany(logs: Array<{
|
|
2122
|
+
level: string;
|
|
2123
|
+
message: string;
|
|
2124
|
+
workerId: string;
|
|
2125
|
+
queue?: string;
|
|
2126
|
+
timestamp: Date;
|
|
2127
|
+
}>): Promise<void>;
|
|
1613
2128
|
/**
|
|
1614
2129
|
* List system logs from the archive.
|
|
1615
2130
|
*/
|
|
@@ -1655,78 +2170,6 @@ declare class SQLitePersistence implements PersistenceAdapter {
|
|
|
1655
2170
|
private setupLogsTable;
|
|
1656
2171
|
}
|
|
1657
2172
|
|
|
1658
|
-
/**
|
|
1659
|
-
* Configuration for a recurring scheduled job.
|
|
1660
|
-
*
|
|
1661
|
-
* @public
|
|
1662
|
-
* @since 3.0.0
|
|
1663
|
-
*/
|
|
1664
|
-
interface ScheduledJobConfig {
|
|
1665
|
-
/** Unique identifier for the scheduled task. */
|
|
1666
|
-
id: string;
|
|
1667
|
-
/** Cron expression defining the schedule (e.g., '* * * * *'). */
|
|
1668
|
-
cron: string;
|
|
1669
|
-
/** The target queue name where the job should be pushed. */
|
|
1670
|
-
queue: string;
|
|
1671
|
-
/** The serialized job data. */
|
|
1672
|
-
job: SerializedJob;
|
|
1673
|
-
/** Timestamp of the last successful execution in milliseconds. */
|
|
1674
|
-
lastRun?: number;
|
|
1675
|
-
/** Timestamp of the next scheduled execution in milliseconds. */
|
|
1676
|
-
nextRun?: number;
|
|
1677
|
-
/** Whether the scheduled job is active. */
|
|
1678
|
-
enabled: boolean;
|
|
1679
|
-
}
|
|
1680
|
-
/**
|
|
1681
|
-
* Scheduler manages recurring (cron) jobs in Gravito.
|
|
1682
|
-
*
|
|
1683
|
-
* It uses Redis to store schedule metadata and coordinates distributed
|
|
1684
|
-
* execution using locks to ensure jobs are triggered exactly once per interval.
|
|
1685
|
-
*
|
|
1686
|
-
* @example
|
|
1687
|
-
* ```typescript
|
|
1688
|
-
* const scheduler = new Scheduler(queueManager);
|
|
1689
|
-
* await scheduler.register({
|
|
1690
|
-
* id: 'daily-cleanup',
|
|
1691
|
-
* cron: '0 0 * * *',
|
|
1692
|
-
* queue: 'default',
|
|
1693
|
-
* job: myJob.serialize()
|
|
1694
|
-
* });
|
|
1695
|
-
* ```
|
|
1696
|
-
*
|
|
1697
|
-
* @public
|
|
1698
|
-
* @since 3.0.0
|
|
1699
|
-
*/
|
|
1700
|
-
declare class Scheduler {
|
|
1701
|
-
private manager;
|
|
1702
|
-
private prefix;
|
|
1703
|
-
constructor(manager: QueueManager, options?: {
|
|
1704
|
-
prefix?: string;
|
|
1705
|
-
});
|
|
1706
|
-
private get client();
|
|
1707
|
-
/**
|
|
1708
|
-
* Register a scheduled job.
|
|
1709
|
-
*/
|
|
1710
|
-
register(config: Omit<ScheduledJobConfig, 'nextRun' | 'enabled'>): Promise<void>;
|
|
1711
|
-
/**
|
|
1712
|
-
* Remove a scheduled job.
|
|
1713
|
-
*/
|
|
1714
|
-
remove(id: string): Promise<void>;
|
|
1715
|
-
/**
|
|
1716
|
-
* List all scheduled jobs.
|
|
1717
|
-
*/
|
|
1718
|
-
list(): Promise<ScheduledJobConfig[]>;
|
|
1719
|
-
/**
|
|
1720
|
-
* Run a scheduled job immediately (out of schedule).
|
|
1721
|
-
*/
|
|
1722
|
-
runNow(id: string): Promise<void>;
|
|
1723
|
-
/**
|
|
1724
|
-
* Process due tasks (TICK).
|
|
1725
|
-
* This should be called periodically (e.g. every minute).
|
|
1726
|
-
*/
|
|
1727
|
-
tick(): Promise<number>;
|
|
1728
|
-
}
|
|
1729
|
-
|
|
1730
2173
|
/**
|
|
1731
2174
|
* Class name serializer (Laravel-style).
|
|
1732
2175
|
*
|
|
@@ -1792,11 +2235,8 @@ declare class JsonSerializer implements JobSerializer {
|
|
|
1792
2235
|
serialize(job: Job): SerializedJob;
|
|
1793
2236
|
/**
|
|
1794
2237
|
* Deserialize a job.
|
|
1795
|
-
*
|
|
1796
|
-
* Note: this implementation only restores properties and does not recreate class instances.
|
|
1797
|
-
* For class instances, use `ClassNameSerializer`.
|
|
1798
2238
|
*/
|
|
1799
2239
|
deserialize(serialized: SerializedJob): Job;
|
|
1800
2240
|
}
|
|
1801
2241
|
|
|
1802
|
-
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 };
|
|
2242
|
+
export { BufferedPersistence, 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 };
|