@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,31 +0,0 @@
1
- import type { QueueManager } from '../QueueManager';
2
- import type { FetchResult, JobSourceOptions, StopSignal } from './types';
3
- /**
4
- * Async Generator,用於從佇列持續抓取 Job。
5
- *
6
- * 封裝所有抓取策略(blocking/batch/sequential),自適應 backoff,
7
- * 以及 rate limit 過濾邏輯。每次 yield 一個 FetchResult,
8
- * 包含本輪抓取的 job 列表和是否使用阻塞模式的資訊。
9
- *
10
- * 設計原則:
11
- * - blocking pop 已在 driver 層等待,不再額外 backoff
12
- * - 自適應退避:空佇列時指數增長,有 job 時重設
13
- * - rate limit:每輪抓取前過濾掉受限的佇列
14
- * - 中止信號:每次 yield 前檢查 signal.aborted
15
- *
16
- * @param queueManager - QueueManager 實例
17
- * @param options - 抓取策略選項
18
- * @param signal - 中止信號(AbortController.signal)
19
- *
20
- * @example
21
- * ```typescript
22
- * const source = jobSourceGenerator(queueManager, options, controller.signal)
23
- *
24
- * for await (const result of source) {
25
- * for (const job of result.jobs) {
26
- * await processJob(job)
27
- * }
28
- * }
29
- * ```
30
- */
31
- export declare function jobSourceGenerator(queueManager: QueueManager, options: JobSourceOptions, signal: StopSignal): AsyncGenerator<FetchResult>;
@@ -1,42 +0,0 @@
1
- import type { Job } from '../Job';
2
- import type { QueueManager } from '../QueueManager';
3
- import type { ConsumerStrategy } from './ConsumerStrategy';
4
- /**
5
- * PollingStrategy implements pull-based job consumption.
6
- *
7
- * Continuously polls queues at adaptive intervals, backing off when empty
8
- * and resetting when jobs are found.
9
- *
10
- * Characteristics:
11
- * - Simple and reliable
12
- * - Predictable polling intervals
13
- * - Higher latency and resource usage vs reactive
14
- * - No external dependencies (works with any driver)
15
- *
16
- * @public
17
- */
18
- export declare class PollingStrategy implements ConsumerStrategy {
19
- private queueManager;
20
- private queues;
21
- private connectionName;
22
- private options;
23
- private running;
24
- constructor(queueManager: QueueManager, queues: string[], connectionName: string, options: {
25
- minPollInterval: number;
26
- maxPollInterval: number;
27
- backoffMultiplier: number;
28
- batchSize: number;
29
- useBlocking: boolean;
30
- blockingTimeout: number;
31
- concurrency: number;
32
- stats: {
33
- active: number;
34
- };
35
- debug: boolean;
36
- log: (message: string, data?: unknown) => void;
37
- });
38
- start(): Promise<void>;
39
- stop(): Promise<void>;
40
- isRunning(): boolean;
41
- fetchJobs(): Promise<Job[]>;
42
- }
@@ -1,41 +0,0 @@
1
- import type { Job } from '../Job';
2
- import type { QueueManager } from '../QueueManager';
3
- import type { ConsumerStrategy } from './ConsumerStrategy';
4
- /**
5
- * ReactiveStrategy implements push-based job consumption.
6
- *
7
- * Listens for queue notifications and pulls jobs reactively when they arrive.
8
- * Implements drain-loop pattern with optional polling fallback.
9
- *
10
- * Characteristics:
11
- * - Low latency (immediate job pickup)
12
- * - Efficient resource usage (no continuous polling)
13
- * - Requires driver support for onNotify()
14
- * - Includes polling fallback to prevent starvation
15
- *
16
- * @public
17
- */
18
- export declare class ReactiveStrategy implements ConsumerStrategy {
19
- private queueManager;
20
- private queues;
21
- private connectionName;
22
- private options;
23
- private running;
24
- private lastNotificationTime;
25
- private fallbackPollingTimer;
26
- constructor(queueManager: QueueManager, queues: string[], connectionName: string, options: {
27
- concurrency: number;
28
- batchSize: number;
29
- stats: {
30
- active: number;
31
- };
32
- reactivePollingFallback: number;
33
- debug: boolean;
34
- log: (message: string, data?: unknown) => void;
35
- });
36
- start(): Promise<void>;
37
- stop(): Promise<void>;
38
- isRunning(): boolean;
39
- fetchJobs(): Promise<Job[]>;
40
- private startFallbackPolling;
41
- }
@@ -1,90 +0,0 @@
1
- import { EventEmitter } from 'node:events';
2
- import type { ConsumerOptions } from '../Consumer';
3
- import type { QueueManager } from '../QueueManager';
4
- import type { ConsumerStats } from './types';
5
- /**
6
- * StreamingConsumer 是 Consumer 管線的核心實作。
7
- *
8
- * 組合以下元件,提供高效能、可測試的 job 消費管線:
9
- * - JobSourceGenerator:抓取 job 的 Async Generator
10
- * - ConcurrencyGate:Promise-based Semaphore,取代 busy-wait
11
- * - GroupSequencer:確保相同 groupId 的 job 依序執行
12
- * - JobExecutor:完整的 job 執行生命週期
13
- * - HeartbeatManager:定時心跳與監控日誌
14
- *
15
- * 主管線採用 `for await...of` 模式,
16
- * 完全消除原始 Consumer 中的 `setTimeout(50)` busy-wait。
17
- *
18
- * @example
19
- * ```typescript
20
- * const streaming = new StreamingConsumer(queueManager, options)
21
- * streaming.on('job:processed', (payload) => console.log('Done:', payload.job.id))
22
- *
23
- * await streaming.start()
24
- * ```
25
- */
26
- export declare class StreamingConsumer extends EventEmitter {
27
- private readonly queueManager;
28
- private readonly options;
29
- private running;
30
- private stopRequested;
31
- private readonly workerId;
32
- private readonly stats;
33
- private gate;
34
- private sequencer;
35
- private heartbeat;
36
- private abortController;
37
- private sharedWorker;
38
- constructor(queueManager: QueueManager, options: ConsumerOptions);
39
- /**
40
- * 啟動主消費管線。
41
- *
42
- * 初始化所有元件,然後進入 `for await...of` 管線迴圈:
43
- * 1. 從 jobSourceGenerator 取得 FetchResult
44
- * 2. 對每個 job,acquire ConcurrencyGate
45
- * 3. 透過 GroupSequencer 確保 group 序列
46
- * 4. 由 JobExecutor 執行 job
47
- * 5. release ConcurrencyGate
48
- *
49
- * @throws {Error} 如果 consumer 已在執行中
50
- */
51
- start(): Promise<void>;
52
- /**
53
- * 請求優雅停止。
54
- *
55
- * 設定 stopRequested 旗標,並中止 generator,
56
- * 等待目前執行中的 job 完成後停止。
57
- *
58
- * @returns 等待完全停止的 Promise
59
- */
60
- requestStop(): Promise<void>;
61
- /**
62
- * 檢查是否仍有 job 在執行中。
63
- */
64
- isActive(): boolean;
65
- /**
66
- * 取得目前的統計資料快照。
67
- */
68
- getStats(): ConsumerStats;
69
- /**
70
- * 重置統計計數器。
71
- */
72
- resetStats(): void;
73
- /**
74
- * Consumer 是否正在執行中。
75
- */
76
- isRunning(): boolean;
77
- /**
78
- * 等待所有正在執行的 job 完成。
79
- */
80
- private waitForAllJobsToComplete;
81
- /**
82
- * 清理所有資源。
83
- */
84
- private cleanup;
85
- /**
86
- * 輸出 debug 日誌(僅在 debug=true 時)。
87
- */
88
- private log;
89
- private createWorkerForExecution;
90
- }
@@ -1,13 +0,0 @@
1
- /**
2
- * Consumer 管線模組 - 重新導出所有公開類型與類別。
3
- *
4
- * 供測試及進階使用者直接引用各個子元件。
5
- */
6
- export { ConcurrencyGate } from './ConcurrencyGate';
7
- export { GroupSequencer } from './GroupSequencer';
8
- export type { HeartbeatManagerOptions } from './HeartbeatManager';
9
- export { HeartbeatManager } from './HeartbeatManager';
10
- export { JobExecutor } from './JobExecutor';
11
- export { jobSourceGenerator } from './JobSourceGenerator';
12
- export { StreamingConsumer } from './StreamingConsumer';
13
- export type { ConsumerStats, ExecutionResult, ExecutorOptions, FetchResult, JobSourceOptions, StopSignal, } from './types';
@@ -1,102 +0,0 @@
1
- import type { Job } from '../Job';
2
- /**
3
- * 從佇列抓取 job 的結果。
4
- *
5
- * JobSourceGenerator 每次 yield 一個 FetchResult,
6
- * 包含本輪抓取的所有 job,以及是否使用阻塞式等待的資訊。
7
- */
8
- export interface FetchResult {
9
- /** 本次抓取到的 job 列表(可能為空) */
10
- jobs: Job[];
11
- /**
12
- * 是否使用了阻塞式 pop(如 BLPOP)。
13
- * 若為 true,代表已在 driver 層等待,不需額外 backoff。
14
- */
15
- didBlock: boolean;
16
- }
17
- /**
18
- * JobSourceGenerator 的選項設定。
19
- */
20
- export interface JobSourceOptions {
21
- /** 要消費的佇列名稱列表 */
22
- queues: string[];
23
- /** 連線名稱,不指定時使用預設連線 */
24
- connection?: string;
25
- /** 每次嘗試抓取的 job 數量,大於 1 時使用批次抓取 */
26
- batchSize: number;
27
- /** 是否使用阻塞式 pop */
28
- useBlocking: boolean;
29
- /** 阻塞式 pop 的逾時秒數 */
30
- blockingTimeout: number;
31
- /** 佇列為空時是否持續存活 */
32
- keepAlive: boolean;
33
- /** 最小輪詢間隔(毫秒) */
34
- minPollInterval: number;
35
- /** 最大輪詢間隔(毫秒) */
36
- maxPollInterval: number;
37
- /** 自適應退避乘數 */
38
- backoffMultiplier: number;
39
- /** Rate limit 設定,key 為佇列名稱 */
40
- rateLimits?: Record<string, {
41
- max: number;
42
- duration: number;
43
- }>;
44
- /** 並發容量 getter,讓 generator 知道可以抓多少 job */
45
- getCapacity: () => number;
46
- }
47
- /**
48
- * JobExecutor 執行選項。
49
- */
50
- export interface ExecutorOptions {
51
- /** debug 模式,會輸出詳細 log */
52
- debug: boolean;
53
- /** Worker ID,用於 log 識別 */
54
- workerId: string;
55
- /** Worker 選項(maxAttempts 等) */
56
- workerOptions?: {
57
- maxAttempts?: number;
58
- };
59
- /** 監控設定 */
60
- monitor?: boolean | {
61
- interval?: number;
62
- extraInfo?: Record<string, unknown>;
63
- prefix?: string;
64
- };
65
- /** 最大請求數量,達到後自動停止 */
66
- maxRequests?: number;
67
- /** 外部事件回呼 */
68
- onEvent?: (event: string, payload: unknown) => void;
69
- }
70
- /**
71
- * JobExecutor 執行一個 job 後的結果。
72
- */
73
- export interface ExecutionResult {
74
- /** job 是否成功完成 */
75
- success: boolean;
76
- /** 執行耗時(毫秒) */
77
- duration: number;
78
- /** 是否因達到 maxRequests 而需要停止 consumer */
79
- shouldStop: boolean;
80
- /** 如果失敗,包含錯誤資訊 */
81
- error?: Error;
82
- }
83
- /**
84
- * Consumer 執行統計資訊。
85
- */
86
- export interface ConsumerStats {
87
- /** 已成功處理的 job 數量 */
88
- processed: number;
89
- /** 失敗(含重試失敗)的 job 數量 */
90
- failed: number;
91
- /** 重試的 job 數量 */
92
- retried: number;
93
- /** 目前正在執行的 job 數量 */
94
- active: number;
95
- }
96
- /**
97
- * 停止訊號,用於 AbortController 整合。
98
- */
99
- export interface StopSignal {
100
- /** 是否已發出停止訊號 */
101
- readonly aborted: boolean;
102
- }
@@ -1,78 +0,0 @@
1
- import type { SerializedJob } from '../types';
2
- /**
3
- * BinaryJobFrame - Gravito Job 的二進制幀格式
4
- *
5
- * 幀結構(Frame Format):
6
- * Magic(2B) + Version(1B) + Flags(1B) + MetaLen(2B Big-Endian) + Metadata(CBOR) + Payload
7
- *
8
- * - Magic:固定為 [0x47, 0x4A]("GJ" = Gravito Job)
9
- * - Version:目前為 0x01
10
- * - Flags:位元旗標,目前定義:
11
- * Bit 0 (HAS_CLASS_NAME):是否包含 className 欄位
12
- * Bit 1 (HAS_GROUP_ID):是否包含 groupId 欄位
13
- * Bit 2 (HAS_DELAY):是否包含 delaySeconds 欄位
14
- * Bit 3 (HAS_PRIORITY):是否包含 priority 欄位
15
- * Bit 4 (HAS_ERROR):是否包含 error / failedAt 欄位
16
- * - MetaLen:Metadata CBOR 資料的長度(2 bytes Big-Endian,最大 65535 bytes)
17
- * - Metadata:以 CBOR 或 JSON 編碼的 metadata 物件(id, createdAt, attempts 等)
18
- * - Payload:原始 Uint8Array 資料(job.data)
19
- *
20
- * @module BinaryJobFrame
21
- */
22
- /** Magic bytes,標識 Gravito Job 二進制幀 */
23
- export declare const MAGIC: readonly [71, 74];
24
- /** 幀格式版本號 */
25
- export declare const VERSION = 1;
26
- /** 幀 header 的固定大小(Magic 2B + Version 1B + Flags 1B + MetaLen 2B = 6 bytes) */
27
- export declare const HEADER_SIZE = 6;
28
- /** Flags 位元定義 */
29
- export declare const Flags: {
30
- /** 包含 className 欄位 */
31
- readonly HAS_CLASS_NAME: 1;
32
- /** 包含 groupId 欄位 */
33
- readonly HAS_GROUP_ID: 2;
34
- /** 包含 delaySeconds 欄位 */
35
- readonly HAS_DELAY: 4;
36
- /** 包含 priority 欄位 */
37
- readonly HAS_PRIORITY: 8;
38
- /** 包含 error / failedAt 欄位 */
39
- readonly HAS_ERROR: 16;
40
- };
41
- /**
42
- * Metadata 短鍵映射(節省序列化空間)
43
- * 完整鍵名 → 短鍵名
44
- */
45
- export declare const META_KEY_MAP: Record<string, string>;
46
- /**
47
- * 短鍵反向映射(反序列化用)
48
- * 短鍵名 → 完整鍵名
49
- */
50
- export declare const META_KEY_REVERSE_MAP: Record<string, string>;
51
- /**
52
- * 判斷給定的資料是否為 Gravito Job 二進制幀
53
- *
54
- * 透過 Magic byte 嗅探識別:檢查前 2 bytes 是否為 [0x47, 0x4A]
55
- *
56
- * @param data - 要檢查的資料(Uint8Array 或 Buffer)
57
- * @returns 如果是 Gravito Job 幀則回傳 true
58
- */
59
- export declare function isGravitoJobFrame(data: Uint8Array | Buffer): boolean;
60
- /**
61
- * 將 SerializedJob 編碼為二進制幀格式
62
- *
63
- * 僅適用於 type === 'binary' 且 data 為 Uint8Array 的 Job。
64
- *
65
- * @param job - 要編碼的 SerializedJob(必須是 binary type)
66
- * @returns 編碼後的 Uint8Array
67
- * @throws {TypeError} 如果 job.data 不是 Uint8Array
68
- * @throws {Error} 如果 metadata 長度超過 65535 bytes
69
- */
70
- export declare function encodeBinaryJobFrame(job: SerializedJob): Uint8Array;
71
- /**
72
- * 將二進制幀解碼為 SerializedJob
73
- *
74
- * @param data - 要解碼的二進制幀(Uint8Array 或 Buffer)
75
- * @returns 解碼後的 SerializedJob,data 為 Uint8Array
76
- * @throws {Error} 如果資料格式無效
77
- */
78
- export declare function decodeBinaryJobFrame(data: Uint8Array | Buffer): SerializedJob;
@@ -1,237 +0,0 @@
1
- import type { JobPushOptions, QueueStats, SerializedJob, TopicOptions } from '../types';
2
- import type { QueueDriver } from './QueueDriver';
3
- /**
4
- * Bull Queue client interface (compatible with bullmq package).
5
- */
6
- export interface BullQueueClient {
7
- add(name: string, data: BullJobData, options?: BullJobOptions): Promise<unknown>;
8
- getJob(id: string): Promise<BullStoredJob | null>;
9
- count(): Promise<number>;
10
- process(handler: (job: BullStoredJob) => Promise<void>): void;
11
- on(event: string, handler: (...args: unknown[]) => void): void;
12
- off(event: string, handler: (...args: unknown[]) => void): void;
13
- pause(): Promise<void>;
14
- resume(): Promise<void>;
15
- clean(grace: number, limit?: number, type?: string): Promise<number>;
16
- close(): Promise<void>;
17
- getJobCounts(types?: string[]): Promise<Record<string, number>>;
18
- getDelayedCount(): Promise<number>;
19
- getFailedCount(): Promise<number>;
20
- getActiveCount(): Promise<number>;
21
- [key: string]: unknown;
22
- }
23
- export interface BullWorkerClient {
24
- [key: string]: unknown;
25
- }
26
- interface BullJobOptions {
27
- priority?: number;
28
- delay?: number;
29
- attempts?: number;
30
- backoff?: {
31
- type: 'exponential';
32
- delay: number;
33
- };
34
- group?: {
35
- id: string;
36
- };
37
- }
38
- interface BullJobData {
39
- id: string;
40
- type: SerializedJob['type'];
41
- data: SerializedJob['data'];
42
- className?: string;
43
- createdAt: number;
44
- delaySeconds?: number;
45
- attempts: number;
46
- maxAttempts: number;
47
- groupId?: string;
48
- retryAfterSeconds?: number;
49
- retryMultiplier?: number;
50
- error?: string;
51
- failedAt?: number;
52
- priority?: string | number;
53
- }
54
- interface BullStoredJob {
55
- moveToFailed?(error: Error, token: boolean): Promise<void>;
56
- }
57
- interface WorkerHeartbeatPayload {
58
- id: string;
59
- status: string;
60
- hostname: string;
61
- pid: number;
62
- uptime: number;
63
- last_ping: string;
64
- queues: string[];
65
- metrics?: Record<string, unknown>;
66
- [key: string]: unknown;
67
- }
68
- interface WorkerLogPayload {
69
- level: string;
70
- message: string;
71
- workerId: string;
72
- jobId?: string;
73
- timestamp: string;
74
- [key: string]: unknown;
75
- }
76
- /**
77
- * Bull Queue driver configuration.
78
- */
79
- export interface BullMQDriverConfig {
80
- /**
81
- * Bull Queue instance (from bullmq package).
82
- */
83
- queue: BullQueueClient;
84
- /**
85
- * Optional Bull Worker instance for processing jobs.
86
- */
87
- worker?: BullWorkerClient;
88
- /**
89
- * Connection options (host, port, etc. for Redis).
90
- */
91
- connection?: {
92
- host?: string;
93
- port?: number;
94
- password?: string;
95
- db?: number;
96
- [key: string]: unknown;
97
- };
98
- /**
99
- * Default number of concurrent workers (default: 1).
100
- */
101
- concurrency?: number;
102
- /**
103
- * Key prefix for namespacing queues (default: 'gravito:').
104
- */
105
- prefix?: string;
106
- /**
107
- * Enable debug logging.
108
- */
109
- debug?: boolean;
110
- }
111
- /**
112
- * Bull Queue driver implementation.
113
- *
114
- * Provides high-performance, persistent job queuing using Bull Queue (backed by Redis).
115
- * Supports priority, delays, retries, and group-based FIFO processing.
116
- *
117
- * @public
118
- * @example
119
- * ```typescript
120
- * import { Queue } from 'bullmq'
121
- * import Redis from 'ioredis'
122
- *
123
- * const redis = new Redis()
124
- * const queue = new Queue('gravito-events', { connection: redis })
125
- * const driver = new BullMQDriver({ queue })
126
- * ```
127
- */
128
- export declare class BullMQDriver implements QueueDriver {
129
- private queue;
130
- private prefix;
131
- private debug;
132
- private queueMap;
133
- constructor(config: BullMQDriverConfig);
134
- /**
135
- * Get or create a queue for the given queue name.
136
- */
137
- private getQueue;
138
- /**
139
- * Build Job Options from JobPushOptions.
140
- */
141
- private buildJobOptions;
142
- /**
143
- * Create Bull job data from SerializedJob.
144
- */
145
- private createBullJobData;
146
- /**
147
- * Pushes a job to Bull Queue.
148
- */
149
- push(queue: string, job: SerializedJob, options?: JobPushOptions): Promise<void>;
150
- /**
151
- * Pops a job from Bull Queue.
152
- * Note: Bull Queue typically uses Workers, not manual pop.
153
- * This is a fallback implementation.
154
- */
155
- pop(queue: string): Promise<SerializedJob | null>;
156
- /**
157
- * Returns the size of the queue.
158
- */
159
- size(queue: string): Promise<number>;
160
- /**
161
- * Clears the queue.
162
- */
163
- clear(queue: string): Promise<void>;
164
- /**
165
- * Marks a job as failed (moves to failed list).
166
- */
167
- fail(queue: string, job: SerializedJob): Promise<void>;
168
- /**
169
- * Returns detailed statistics for the queue.
170
- */
171
- stats(queue: string): Promise<QueueStats>;
172
- /**
173
- * Retrieves failed jobs from the Dead Letter Queue.
174
- */
175
- getFailed(queue: string, _start?: number, _end?: number): Promise<SerializedJob[]>;
176
- /**
177
- * Retries failed jobs.
178
- */
179
- retryFailed(queue: string, _count?: number): Promise<number>;
180
- /**
181
- * Clears the Dead Letter Queue.
182
- */
183
- clearFailed(queue: string): Promise<void>;
184
- /**
185
- * Creates a new queue/topic.
186
- */
187
- createTopic(_topic: string, _options?: TopicOptions): Promise<void>;
188
- /**
189
- * Deletes a queue/topic.
190
- */
191
- deleteTopic(topic: string): Promise<void>;
192
- /**
193
- * Pushes multiple jobs in batch.
194
- */
195
- pushMany(queue: string, jobs: SerializedJob[]): Promise<void>;
196
- /**
197
- * Pops multiple jobs in batch.
198
- */
199
- popMany(_queue: string, _count: number): Promise<SerializedJob[]>;
200
- /**
201
- * Reports worker heartbeat.
202
- */
203
- reportHeartbeat(workerInfo: {
204
- id: string;
205
- status: string;
206
- hostname: string;
207
- pid: number;
208
- uptime: number;
209
- last_ping: string;
210
- queues: string[];
211
- metrics?: Record<string, unknown>;
212
- [key: string]: unknown;
213
- } & WorkerHeartbeatPayload, _prefix?: string): Promise<void>;
214
- /**
215
- * Publishes a log message.
216
- */
217
- publishLog(logPayload: {
218
- level: string;
219
- message: string;
220
- workerId: string;
221
- jobId?: string;
222
- timestamp: string;
223
- [key: string]: unknown;
224
- } & WorkerLogPayload, _prefix?: string): Promise<void>;
225
- /**
226
- * Checks rate limit for a queue.
227
- */
228
- checkRateLimit(_queue: string, _config: {
229
- max: number;
230
- duration: number;
231
- }): Promise<boolean>;
232
- /**
233
- * Retrieves all queue names.
234
- */
235
- getQueues(): Promise<string[]>;
236
- }
237
- export {};