@gravito/stream 2.1.2 → 3.0.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.
Files changed (75) hide show
  1. package/package.json +1 -1
  2. package/dist/BatchConsumer.d.ts +0 -81
  3. package/dist/Consumer.d.ts +0 -215
  4. package/dist/DashboardProvider.d.ts +0 -29
  5. package/dist/Job.d.ts +0 -183
  6. package/dist/OrbitStream.d.ts +0 -151
  7. package/dist/QueueManager.d.ts +0 -321
  8. package/dist/Queueable.d.ts +0 -91
  9. package/dist/Scheduler.d.ts +0 -215
  10. package/dist/StreamEventBackend.d.ts +0 -120
  11. package/dist/SystemEventJob.d.ts +0 -41
  12. package/dist/Worker.d.ts +0 -139
  13. package/dist/benchmarks/PerformanceReporter.d.ts +0 -99
  14. package/dist/consumer/ConcurrencyGate.d.ts +0 -55
  15. package/dist/consumer/ConsumerStrategy.d.ts +0 -41
  16. package/dist/consumer/GroupSequencer.d.ts +0 -57
  17. package/dist/consumer/HeartbeatManager.d.ts +0 -65
  18. package/dist/consumer/JobExecutor.d.ts +0 -61
  19. package/dist/consumer/JobSourceGenerator.d.ts +0 -31
  20. package/dist/consumer/PollingStrategy.d.ts +0 -42
  21. package/dist/consumer/ReactiveStrategy.d.ts +0 -41
  22. package/dist/consumer/StreamingConsumer.d.ts +0 -90
  23. package/dist/consumer/index.d.ts +0 -13
  24. package/dist/consumer/types.d.ts +0 -102
  25. package/dist/drivers/BinaryJobFrame.d.ts +0 -78
  26. package/dist/drivers/BullMQDriver.d.ts +0 -237
  27. package/dist/drivers/DatabaseDriver.d.ts +0 -131
  28. package/dist/drivers/GrpcDriver.d.ts +0 -16
  29. package/dist/drivers/KafkaDriver.d.ts +0 -161
  30. package/dist/drivers/MemoryDriver.d.ts +0 -119
  31. package/dist/drivers/QueueDriver.d.ts +0 -250
  32. package/dist/drivers/RabbitMQDriver.d.ts +0 -140
  33. package/dist/drivers/RedisDriver.d.ts +0 -328
  34. package/dist/drivers/SQSDriver.d.ts +0 -114
  35. package/dist/drivers/kafka/BackpressureController.d.ts +0 -60
  36. package/dist/drivers/kafka/BatchProcessor.d.ts +0 -50
  37. package/dist/drivers/kafka/ConsumerLifecycleManager.d.ts +0 -80
  38. package/dist/drivers/kafka/ErrorCategorizer.d.ts +0 -39
  39. package/dist/drivers/kafka/ErrorRecoveryManager.d.ts +0 -100
  40. package/dist/drivers/kafka/HeartbeatManager.d.ts +0 -57
  41. package/dist/drivers/kafka/KafkaDriver.d.ts +0 -138
  42. package/dist/drivers/kafka/KafkaMetrics.d.ts +0 -88
  43. package/dist/drivers/kafka/KafkaNotifier.d.ts +0 -70
  44. package/dist/drivers/kafka/MessageBuffer.d.ts +0 -71
  45. package/dist/drivers/kafka/OffsetTracker.d.ts +0 -65
  46. package/dist/drivers/kafka/PerformanceMonitor.d.ts +0 -88
  47. package/dist/drivers/kafka/RateLimiter.d.ts +0 -52
  48. package/dist/drivers/kafka/RebalanceHandler.d.ts +0 -104
  49. package/dist/drivers/kafka/RingBuffer.d.ts +0 -63
  50. package/dist/drivers/kafka/index.d.ts +0 -22
  51. package/dist/drivers/kafka/types.d.ts +0 -553
  52. package/dist/drivers/prepareJobForTransport.d.ts +0 -10
  53. package/dist/index.d.ts +0 -69
  54. package/dist/locks/DistributedLock.d.ts +0 -175
  55. package/dist/persistence/BufferedPersistence.d.ts +0 -130
  56. package/dist/persistence/BunBufferedPersistence.d.ts +0 -173
  57. package/dist/persistence/MySQLPersistence.d.ts +0 -134
  58. package/dist/persistence/SQLitePersistence.d.ts +0 -133
  59. package/dist/serializers/BinarySerializer.d.ts +0 -42
  60. package/dist/serializers/CachedSerializer.d.ts +0 -42
  61. package/dist/serializers/CborNativeSerializer.d.ts +0 -56
  62. package/dist/serializers/ClassNameSerializer.d.ts +0 -58
  63. package/dist/serializers/JobSerializer.d.ts +0 -33
  64. package/dist/serializers/JsonSerializer.d.ts +0 -28
  65. package/dist/serializers/JsonlSerializer.d.ts +0 -90
  66. package/dist/serializers/MessagePackSerializer.d.ts +0 -29
  67. package/dist/types.d.ts +0 -672
  68. package/dist/workers/BinaryWorkerProtocol.d.ts +0 -77
  69. package/dist/workers/BunWorker.d.ts +0 -179
  70. package/dist/workers/SandboxedWorker.d.ts +0 -132
  71. package/dist/workers/WorkerFactory.d.ts +0 -128
  72. package/dist/workers/WorkerPool.d.ts +0 -186
  73. package/dist/workers/bun-job-executor.d.ts +0 -14
  74. package/dist/workers/index.d.ts +0 -13
  75. package/dist/workers/job-executor.d.ts +0 -9
@@ -1,131 +0,0 @@
1
- import type { QueueStats, SerializedJob } from '../types';
2
- import type { QueueDriver } from './QueueDriver';
3
- /**
4
- * Generic database service interface.
5
- *
6
- * Adapts any SQL database client (e.g., pg, mysql2, sqlite3) for use with the DatabaseDriver.
7
- * Users must provide an implementation of this interface that wraps their specific DB library.
8
- */
9
- export interface DatabaseService {
10
- /**
11
- * Execute a raw SQL query.
12
- *
13
- * @param sql - The SQL query string with placeholders (e.g., $1, ?).
14
- * @param bindings - The values to bind to the placeholders.
15
- * @returns The query result (rows or metadata).
16
- */
17
- execute<T = unknown>(sql: string, bindings?: unknown[]): Promise<T[] | T>;
18
- /**
19
- * Execute multiple queries within a single transaction.
20
- *
21
- * @param callback - A function that receives a transaction-scoped service instance.
22
- * @returns The result of the callback.
23
- */
24
- transaction<T>(callback: (tx: DatabaseService) => Promise<T>): Promise<T>;
25
- }
26
- /**
27
- * Configuration options for the DatabaseDriver.
28
- */
29
- export interface DatabaseDriverConfig {
30
- /**
31
- * The name of the table used to store jobs.
32
- * @default 'jobs'
33
- */
34
- table?: string;
35
- /**
36
- * The database service adapter instance.
37
- */
38
- dbService?: DatabaseService;
39
- }
40
- /**
41
- * Database-backed queue driver.
42
- *
43
- * Persists jobs in a SQL database table. Supports delayed jobs, reservation (locking),
44
- * and reliable delivery. Compatible with PostgreSQL (SKIP LOCKED), MySQL, and SQLite.
45
- *
46
- * @public
47
- * @example
48
- * ```typescript
49
- * const driver = new DatabaseDriver({
50
- * dbService: myDbAdapter,
51
- * table: 'queue_jobs'
52
- * });
53
- * ```
54
- */
55
- export declare class DatabaseDriver implements QueueDriver {
56
- private tableName;
57
- private dbService;
58
- constructor(config: DatabaseDriverConfig);
59
- /**
60
- * Pushes a job to the database queue.
61
- *
62
- * Inserts a new row into the jobs table.
63
- *
64
- * @param queue - The queue name.
65
- * @param job - The serialized job.
66
- */
67
- push(queue: string, job: SerializedJob): Promise<void>;
68
- /**
69
- * Pops the next available job from the queue.
70
- *
71
- * Uses transactional locking (SELECT ... FOR UPDATE SKIP LOCKED if supported) to ensure
72
- * atomic reservation of jobs by workers.
73
- *
74
- * @param queue - The queue name.
75
- * @returns The job or `null`.
76
- */
77
- pop(queue: string): Promise<SerializedJob | null>;
78
- /**
79
- * Pops multiple jobs from the queue in a single transaction.
80
- *
81
- * @param queue - The queue name.
82
- * @param count - Max jobs to pop.
83
- */
84
- popMany(queue: string, count: number): Promise<SerializedJob[]>;
85
- /**
86
- * Retrieves queue statistics by querying the table.
87
- *
88
- * @param queue - The queue name.
89
- */
90
- stats(queue: string): Promise<QueueStats>;
91
- /**
92
- * Returns the count of pending jobs.
93
- *
94
- * @param queue - The queue name.
95
- */
96
- size(queue: string): Promise<number>;
97
- /**
98
- * Clears the queue by deleting all rows for the queue.
99
- *
100
- * @param queue - The queue name.
101
- */
102
- clear(queue: string): Promise<void>;
103
- /**
104
- * Pops a job using a polling loop (Blocking simulation).
105
- *
106
- * @param queue - The queue name.
107
- * @param timeout - Timeout in seconds.
108
- */
109
- popBlocking(queue: string, timeout: number): Promise<SerializedJob | null>;
110
- /**
111
- * Pushes multiple jobs using a transaction.
112
- *
113
- * @param queue - The queue name.
114
- * @param jobs - Array of jobs.
115
- */
116
- pushMany(queue: string, jobs: SerializedJob[]): Promise<void>;
117
- /**
118
- * Marks a job as permanently failed by moving it to the DLQ (separate logical queue in DB).
119
- *
120
- * @param queue - The queue name.
121
- * @param job - The failed job.
122
- */
123
- fail(queue: string, job: SerializedJob): Promise<void>;
124
- /**
125
- * Deletes a job row from the database (completion).
126
- *
127
- * @param _queue - The queue name (unused).
128
- * @param job - The job to complete.
129
- */
130
- complete(_queue: string, job: SerializedJob): Promise<void>;
131
- }
@@ -1,16 +0,0 @@
1
- import type { GrpcDriverConfig, JobPushOptions, QueueStats, SerializedJob } from '../types';
2
- import type { QueueDriver } from './QueueDriver';
3
- export type { GrpcDriverConfig } from '../types';
4
- export declare class GrpcDriver implements QueueDriver {
5
- private client;
6
- constructor(config: GrpcDriverConfig);
7
- private getCredentials;
8
- push(queue: string, job: SerializedJob, options?: JobPushOptions): Promise<void>;
9
- pop(queue: string): Promise<SerializedJob | null>;
10
- size(queue: string): Promise<number>;
11
- clear(queue: string): Promise<void>;
12
- acknowledge(messageId: string): Promise<void>;
13
- stats(queue: string): Promise<QueueStats>;
14
- private toProtoJob;
15
- private fromProtoJob;
16
- }
@@ -1,161 +0,0 @@
1
- import type { SerializedJob, TopicOptions } from '../types';
2
- import type { QueueDriver } from './QueueDriver';
3
- /**
4
- * Kafka driver configuration.
5
- */
6
- export interface KafkaDriverConfig {
7
- /**
8
- * Kafka client instance (kafkajs).
9
- *
10
- * Must provide producer, admin, and consumer factories compatible with KafkaJS.
11
- */
12
- client: {
13
- producer: () => {
14
- connect: () => Promise<void>;
15
- send: (args: {
16
- topic: string;
17
- messages: Array<{
18
- key?: string;
19
- value: string;
20
- }>;
21
- }) => Promise<void>;
22
- disconnect: () => Promise<void>;
23
- };
24
- admin: () => {
25
- connect: () => Promise<void>;
26
- createTopics: (args: {
27
- topics: Array<{
28
- topic: string;
29
- numPartitions?: number;
30
- replicationFactor?: number;
31
- }>;
32
- }) => Promise<void>;
33
- deleteTopics: (args: {
34
- topics: string[];
35
- }) => Promise<void>;
36
- disconnect: () => Promise<void>;
37
- };
38
- consumer: (args: {
39
- groupId: string;
40
- }) => {
41
- connect: () => Promise<void>;
42
- subscribe: (args: {
43
- topics: string[];
44
- }) => Promise<void>;
45
- run: (args: KafkaConsumerRunOptions) => Promise<void>;
46
- disconnect: () => Promise<void>;
47
- };
48
- };
49
- /**
50
- * Consumer group ID used for reading messages.
51
- * @default 'gravito-workers'
52
- */
53
- consumerGroupId?: string;
54
- }
55
- interface KafkaMessage {
56
- key?: Buffer;
57
- value: Buffer | null;
58
- offset: string;
59
- }
60
- interface KafkaBatch {
61
- messages: KafkaMessage[];
62
- }
63
- interface KafkaEachBatchPayload {
64
- batch: KafkaBatch;
65
- resolveOffset(offset: string): void;
66
- heartbeat(): Promise<void>;
67
- isRunning(): boolean;
68
- }
69
- interface KafkaConsumerRunOptions {
70
- eachMessage?: (args: {
71
- topic: string;
72
- partition: number;
73
- message: KafkaMessage;
74
- }) => Promise<void>;
75
- eachBatch?: (args: KafkaEachBatchPayload) => Promise<void>;
76
- }
77
- /**
78
- * Kafka-backed queue driver.
79
- *
80
- * Uses Apache Kafka topics as queues. Designed for high-throughput streaming
81
- * rather than traditional job queue semantics (pop/delete).
82
- * Supports push-based consumption via `subscribe()`.
83
- *
84
- * @public
85
- * @example
86
- * ```typescript
87
- * const driver = new KafkaDriver({ client: kafka, consumerGroupId: 'my-app' });
88
- * ```
89
- */
90
- export declare class KafkaDriver implements QueueDriver {
91
- private client;
92
- private consumerGroupId;
93
- private producer?;
94
- private admin?;
95
- constructor(config: KafkaDriverConfig);
96
- /**
97
- * Ensure the producer is connected.
98
- */
99
- private ensureProducer;
100
- /**
101
- * Ensure the admin client is connected.
102
- */
103
- private ensureAdmin;
104
- /**
105
- * Pushes a job to a Kafka topic.
106
- *
107
- * @param queue - The topic name.
108
- * @param job - The job to publish.
109
- */
110
- push(queue: string, job: SerializedJob): Promise<void>;
111
- /**
112
- * Pop is not supported for Kafka (Push-based).
113
- *
114
- * Kafka consumers typically stream messages. Use `subscribe()` instead.
115
- *
116
- * @throws {Error} Always throws as Kafka does not support polling individual messages in this manner.
117
- */
118
- pop(_queue: string): Promise<SerializedJob | null>;
119
- /**
120
- * Returns 0 as Kafka does not expose a simple "queue size".
121
- *
122
- * Monitoring lag requires external tools or Admin API checks not implemented here.
123
- */
124
- size(_queue: string): Promise<number>;
125
- /**
126
- * Clears a queue by deleting the topic.
127
- *
128
- * @param queue - The topic name.
129
- */
130
- clear(queue: string): Promise<void>;
131
- /**
132
- * Pushes multiple jobs to a Kafka topic.
133
- *
134
- * @param queue - The topic name.
135
- * @param jobs - Array of jobs.
136
- */
137
- pushMany(queue: string, jobs: SerializedJob[]): Promise<void>;
138
- /**
139
- * Creates a new Kafka topic.
140
- *
141
- * @param topic - The topic name.
142
- * @param options - Config for partitions/replication.
143
- */
144
- createTopic(topic: string, options?: TopicOptions): Promise<void>;
145
- /**
146
- * Deletes a Kafka topic.
147
- *
148
- * @param topic - The topic name.
149
- */
150
- deleteTopic(topic: string): Promise<void>;
151
- /**
152
- * Subscribes to a topic for streaming jobs.
153
- *
154
- * Starts a Kafka consumer group and processes messages as they arrive.
155
- *
156
- * @param queue - The topic name.
157
- * @param callback - Function to handle the job.
158
- */
159
- subscribe(queue: string, callback: (job: SerializedJob) => Promise<void>): Promise<void>;
160
- }
161
- export {};
@@ -1,119 +0,0 @@
1
- import type { QueueStats, SerializedJob } from '../types';
2
- import type { QueueDriver } from './QueueDriver';
3
- /**
4
- * Configuration options for the MemoryDriver.
5
- */
6
- export interface MemoryDriverConfig {
7
- /**
8
- * The maximum number of jobs allowed in a single queue.
9
- *
10
- * @default Infinity
11
- */
12
- maxSize?: number;
13
- }
14
- /**
15
- * In-memory queue driver.
16
- *
17
- * Stores jobs in a local JavaScript Map. Ideal for development, testing, and simple
18
- * use cases where persistence across restarts is not required.
19
- * It supports basic delay handling but data is volatile.
20
- *
21
- * @public
22
- * @example
23
- * ```typescript
24
- * const driver = new MemoryDriver({ maxSize: 1000 });
25
- * await driver.push('default', job);
26
- * ```
27
- */
28
- export declare class MemoryDriver implements QueueDriver {
29
- private queues;
30
- private maxSize;
31
- private readonly callbacks;
32
- private notificationsEnabled;
33
- constructor(config?: MemoryDriverConfig);
34
- /**
35
- * Pushes a job to the in-memory queue.
36
- *
37
- * @param queue - The queue name.
38
- * @param job - The serialized job.
39
- * @throws {Error} If the queue has reached `maxSize`.
40
- */
41
- push(queue: string, job: SerializedJob): Promise<void>;
42
- /**
43
- * Pops the next available job from the queue.
44
- *
45
- * Respects `delaySeconds` by checking the job's `createdAt` timestamp.
46
- *
47
- * @param queue - The queue name.
48
- * @returns The job or `null`.
49
- */
50
- pop(queue: string): Promise<SerializedJob | null>;
51
- /**
52
- * Returns the number of jobs in the queue.
53
- *
54
- * @param queue - The queue name.
55
- */
56
- size(queue: string): Promise<number>;
57
- /**
58
- * Clears all jobs from the queue.
59
- *
60
- * @param queue - The queue name.
61
- */
62
- clear(queue: string): Promise<void>;
63
- /**
64
- * Moves a job to the failed (DLQ) list.
65
- *
66
- * In MemoryDriver, this simply pushes to a `failed:{queue}` list.
67
- *
68
- * @param queue - The original queue name.
69
- * @param job - The failed job.
70
- */
71
- fail(queue: string, job: SerializedJob): Promise<void>;
72
- /**
73
- * Retrieves statistics for the queue.
74
- *
75
- * Calculates pending, delayed, and failed counts by iterating through the list.
76
- *
77
- * @param queue - The queue name.
78
- */
79
- stats(queue: string): Promise<QueueStats>;
80
- /**
81
- * Pushes multiple jobs to the queue.
82
- *
83
- * @param queue - The queue name.
84
- * @param jobs - Array of jobs.
85
- */
86
- pushMany(queue: string, jobs: SerializedJob[]): Promise<void>;
87
- /**
88
- * Pops multiple jobs from the queue.
89
- *
90
- * @param queue - The queue name.
91
- * @param count - Max jobs to pop.
92
- */
93
- popMany(queue: string, count: number): Promise<SerializedJob[]>;
94
- /**
95
- * Lists all active queues in memory.
96
- */
97
- getQueues(): Promise<string[]>;
98
- /**
99
- * Enable notifications for this driver.
100
- */
101
- enableNotifications(): Promise<void>;
102
- /**
103
- * Disable notifications for this driver.
104
- */
105
- disableNotifications(): Promise<void>;
106
- /**
107
- * Register a notification callback for specific queues.
108
- *
109
- * @param queues - The queue names.
110
- * @param callback - The callback function.
111
- */
112
- onNotify(queues: string | string[], callback: (queue: string) => Promise<void>): Promise<void>;
113
- /**
114
- * Internal notify helper.
115
- *
116
- * @param queue - The queue name.
117
- */
118
- private notify;
119
- }
@@ -1,250 +0,0 @@
1
- import type { JobPushOptions, QueueStats, SerializedJob, TopicOptions } from '../types';
2
- /**
3
- * Queue driver interface.
4
- *
5
- * Defines the contract that all storage backends (Redis, Database, SQS, etc.) must implement
6
- * to be compatible with the QueueManager. It covers the basic operations for a job queue:
7
- * push, pop, size, and clear.
8
- *
9
- * Advanced capabilities like rate limiting, reliable delivery (acknowledgements), and
10
- * batch operations are optional but recommended for high-performance drivers.
11
- *
12
- * @public
13
- * @example
14
- * ```typescript
15
- * class MyCustomDriver implements QueueDriver {
16
- * async push(queue: string, job: SerializedJob) {
17
- * // ... write to storage
18
- * }
19
- * async pop(queue: string) {
20
- * // ... read from storage
21
- * return job;
22
- * }
23
- * async size(queue: string) { return 0; }
24
- * async clear(queue: string) {}
25
- * }
26
- * ```
27
- */
28
- export interface QueueDriver {
29
- /**
30
- * Pushes a job onto the specified queue.
31
- *
32
- * @param queue - The name of the queue.
33
- * @param job - The serialized job data.
34
- * @param options - Optional parameters like priority or group ID.
35
- * @returns A promise that resolves when the job is successfully stored.
36
- */
37
- push(queue: string, job: SerializedJob, options?: JobPushOptions): Promise<void>;
38
- /**
39
- * Retrieves and removes the next job from the queue (FIFO).
40
- *
41
- * @param queue - The name of the queue.
42
- * @returns The serialized job if available, or `null` if the queue is empty.
43
- */
44
- pop(queue: string): Promise<SerializedJob | null>;
45
- /**
46
- * Blocking version of `pop`. Waits for a job to arrive if the queue is empty.
47
- *
48
- * @param queues - A single queue name or an array of queues to listen to.
49
- * @param timeout - The maximum time to wait in seconds (0 means indefinite).
50
- * @returns The serialized job if one arrives within the timeout, or `null`.
51
- */
52
- popBlocking?(queues: string | string[], timeout: number): Promise<SerializedJob | null>;
53
- /**
54
- * Marks a job as completed.
55
- *
56
- * Used primarily by drivers that support advanced flow control (like FIFO groups)
57
- * or explicit acknowledgement (like SQS/RabbitMQ).
58
- *
59
- * @param queue - The name of the queue.
60
- * @param job - The job that was completed.
61
- */
62
- complete?(queue: string, job: SerializedJob): Promise<void>;
63
- /**
64
- * Returns the number of jobs currently waiting in the queue.
65
- *
66
- * @param queue - The name of the queue.
67
- * @returns The count of pending jobs.
68
- */
69
- size(queue: string): Promise<number>;
70
- /**
71
- * Removes all jobs from the specified queue.
72
- *
73
- * @param queue - The name of the queue to purge.
74
- */
75
- clear(queue: string): Promise<void>;
76
- /**
77
- * Moves a job to the Dead Letter Queue (DLQ) after repeated failures.
78
- *
79
- * @param queue - The original queue name.
80
- * @param job - The job data (usually including error information).
81
- */
82
- fail?(queue: string, job: SerializedJob): Promise<void>;
83
- /**
84
- * Retrieves detailed statistics for a queue.
85
- *
86
- * @param queue - The name of the queue.
87
- * @returns An object containing counts for pending, delayed, failed, etc.
88
- */
89
- stats?(queue: string): Promise<QueueStats>;
90
- /**
91
- * Pushes multiple jobs to the queue in a single batch operation.
92
- *
93
- * @param queue - The name of the queue.
94
- * @param jobs - An array of serialized jobs.
95
- */
96
- pushMany?(queue: string, jobs: SerializedJob[]): Promise<void>;
97
- /**
98
- * Retrieves multiple jobs from the queue in a single batch operation.
99
- *
100
- * @param queue - The name of the queue.
101
- * @param count - The maximum number of jobs to retrieve.
102
- * @returns An array of serialized jobs.
103
- */
104
- popMany?(queue: string, count: number): Promise<SerializedJob[]>;
105
- /**
106
- * Acknowledges a specific message by its ID.
107
- *
108
- * Used for drivers that require explicit acknowledgement (e.g., SQS, Kafka).
109
- *
110
- * @param messageId - The ID of the message to acknowledge.
111
- */
112
- acknowledge?(messageId: string): Promise<void>;
113
- /**
114
- * Subscribes to a queue for real-time job processing (Push model).
115
- *
116
- * Alternative to polling (`pop`). The driver pushes jobs to the callback as they arrive.
117
- *
118
- * @param queue - The name of the queue.
119
- * @param callback - The function to call when a job is received.
120
- */
121
- subscribe?(queue: string, callback: (job: SerializedJob) => Promise<void>): Promise<void>;
122
- /**
123
- * Creates a new topic or queue (for drivers like Kafka/RabbitMQ).
124
- *
125
- * @param topic - The name of the topic/queue.
126
- * @param options - Configuration options (partitions, replication, etc.).
127
- */
128
- createTopic?(topic: string, options?: TopicOptions): Promise<void>;
129
- /**
130
- * Deletes a topic or queue.
131
- *
132
- * @param topic - The name of the topic/queue to delete.
133
- */
134
- deleteTopic?(topic: string): Promise<void>;
135
- /**
136
- * Sends a heartbeat signal for a worker instance.
137
- *
138
- * Used for monitoring worker health and presence.
139
- *
140
- * @param workerInfo - Metadata about the worker (ID, status, resources).
141
- * @param prefix - Optional key prefix for storage.
142
- */
143
- reportHeartbeat?(workerInfo: {
144
- id: string;
145
- status: string;
146
- hostname: string;
147
- pid: number;
148
- uptime: number;
149
- last_ping: string;
150
- queues: string[];
151
- metrics?: Record<string, unknown>;
152
- [key: string]: unknown;
153
- }, prefix?: string): Promise<void>;
154
- /**
155
- * Publishes a log entry to the monitoring system.
156
- *
157
- * @param logPayload - The log data (level, message, context).
158
- * @param prefix - Optional key prefix.
159
- */
160
- publishLog?(logPayload: {
161
- level: string;
162
- message: string;
163
- workerId: string;
164
- jobId?: string;
165
- timestamp: string;
166
- [key: string]: unknown;
167
- }, prefix?: string): Promise<void>;
168
- /**
169
- * Checks if a specific queue has exceeded its rate limit.
170
- *
171
- * @param queue - The name of the queue.
172
- * @param config - The rate limit rules (max jobs per duration).
173
- * @returns `true` if the job is allowed to proceed, `false` if limited.
174
- */
175
- checkRateLimit?(queue: string, config: {
176
- max: number;
177
- duration: number;
178
- }): Promise<boolean>;
179
- /**
180
- * Retries failed jobs from the Dead Letter Queue.
181
- *
182
- * Moves jobs from the DLQ back to the active queue.
183
- *
184
- * @param queue - The name of the queue.
185
- * @param count - The number of jobs to retry (optional).
186
- * @returns The number of jobs actually moved.
187
- */
188
- retryFailed?(queue: string, count?: number): Promise<number>;
189
- /**
190
- * Retrieves a list of failed jobs from the Dead Letter Queue.
191
- *
192
- * @param queue - The name of the queue.
193
- * @param start - Pagination start index.
194
- * @param end - Pagination end index.
195
- * @returns An array of failed jobs.
196
- */
197
- getFailed?(queue: string, start?: number, end?: number): Promise<SerializedJob[]>;
198
- /**
199
- * Clears the Dead Letter Queue for a specific queue.
200
- *
201
- * @param queue - The name of the queue.
202
- */
203
- clearFailed?(queue: string): Promise<void>;
204
- /**
205
- * Lists all queues managed by this driver.
206
- *
207
- * Useful for monitoring dashboards to discover active queues dynamically.
208
- *
209
- * @returns A list of queue names.
210
- */
211
- getQueues?(): Promise<string[]>;
212
- /**
213
- * Registers a notification listener for when jobs arrive in a queue.
214
- *
215
- * Only sends the queue name as notification, not the job data itself.
216
- * The consumer is responsible for pulling jobs from the queue.
217
- * This enables reactive pull-based consumption with low latency.
218
- *
219
- * @param queues - One or more queue names to listen for notifications.
220
- * @param callback - Called when a job arrives in any of the queues, with the queue name.
221
- * @returns A promise that resolves when the listener is registered.
222
- *
223
- * @example
224
- * ```typescript
225
- * driver.onNotify(['emails', 'sms'], (queue) => {
226
- * console.log(`Job arrived in ${queue}`);
227
- * // Consumer will pull from this queue reactively
228
- * });
229
- * ```
230
- */
231
- onNotify?(queues: string | string[], callback: (queue: string) => Promise<void>): Promise<void>;
232
- /**
233
- * Enables real-time notifications for job arrivals.
234
- *
235
- * Activates the notification mechanism so that `onNotify` callbacks are invoked.
236
- * Called once during consumer startup.
237
- *
238
- * @returns A promise that resolves when notifications are enabled.
239
- */
240
- enableNotifications?(): Promise<void>;
241
- /**
242
- * Disables real-time notifications for job arrivals.
243
- *
244
- * Stops the notification mechanism to prevent further `onNotify` callbacks.
245
- * Called during consumer shutdown.
246
- *
247
- * @returns A promise that resolves when notifications are disabled.
248
- */
249
- disableNotifications?(): Promise<void>;
250
- }