@gravito/stream 2.1.0 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/DashboardProvider.d.ts +10 -1
- package/dist/QueueManager.d.ts +2 -0
- package/dist/Scheduler.d.ts +1 -0
- package/dist/StreamEventBackend.d.ts +7 -1
- package/dist/SystemEventJob.d.ts +10 -2
- package/dist/consumer/StreamingConsumer.d.ts +2 -0
- package/dist/drivers/BullMQDriver.d.ts +64 -13
- package/dist/drivers/KafkaDriver.d.ts +24 -11
- package/dist/drivers/MemoryDriver.d.ts +15 -4
- package/dist/drivers/QueueDriver.d.ts +3 -3
- package/dist/drivers/RabbitMQDriver.d.ts +44 -6
- package/dist/drivers/RedisDriver.d.ts +41 -7
- package/dist/drivers/SQSDriver.d.ts +3 -0
- package/dist/drivers/kafka/KafkaNotifier.d.ts +16 -0
- package/dist/drivers/kafka/OffsetTracker.d.ts +2 -0
- package/dist/index.cjs +60 -7950
- package/dist/index.cjs.map +3 -65
- package/dist/index.js +2 -7916
- package/dist/index.js.map +3 -65
- package/dist/persistence/BufferedPersistence.d.ts +1 -1
- package/dist/persistence/BunBufferedPersistence.d.ts +1 -1
- package/dist/persistence/MySQLPersistence.d.ts +1 -1
- package/dist/persistence/SQLitePersistence.d.ts +1 -1
- package/dist/serializers/CachedSerializer.d.ts +4 -0
- package/dist/types.d.ts +27 -8
- package/dist/workers/WorkerFactory.d.ts +2 -2
- package/package.json +3 -3
|
@@ -1,4 +1,12 @@
|
|
|
1
|
+
import type { GravitoContext } from '@gravito/core';
|
|
1
2
|
import type { QueueManager } from './QueueManager';
|
|
3
|
+
interface DashboardRouter {
|
|
4
|
+
get(path: string, handler: (context: GravitoContext) => Promise<Response | unknown> | Response | unknown): void;
|
|
5
|
+
post(path: string, handler: (context: GravitoContext) => Promise<Response | unknown> | Response | unknown): void;
|
|
6
|
+
}
|
|
7
|
+
interface DashboardCore {
|
|
8
|
+
adapter: DashboardRouter;
|
|
9
|
+
}
|
|
2
10
|
/**
|
|
3
11
|
* Provides API routes for the Stream Monitoring Dashboard.
|
|
4
12
|
*
|
|
@@ -16,5 +24,6 @@ export declare class DashboardProvider {
|
|
|
16
24
|
* @param core - The PlanetCore instance.
|
|
17
25
|
* @param basePath - The base path for API routes (default: '/_flux').
|
|
18
26
|
*/
|
|
19
|
-
registerRoutes(core:
|
|
27
|
+
registerRoutes(core: DashboardCore, basePath?: string): void;
|
|
20
28
|
}
|
|
29
|
+
export {};
|
package/dist/QueueManager.d.ts
CHANGED
package/dist/Scheduler.d.ts
CHANGED
|
@@ -8,6 +8,11 @@ import type { QueueManager } from './QueueManager';
|
|
|
8
8
|
* - 'hybrid': Bull retries + Core DLQ fallback (future phase)
|
|
9
9
|
*/
|
|
10
10
|
export type RetryStrategy = 'bull' | 'core' | 'hybrid';
|
|
11
|
+
interface CircuitBreakerLike {
|
|
12
|
+
getState?(): string;
|
|
13
|
+
recordFailure?(error: Error): void;
|
|
14
|
+
recordSuccess?(): void;
|
|
15
|
+
}
|
|
11
16
|
/**
|
|
12
17
|
* Configuration for StreamEventBackend.
|
|
13
18
|
*/
|
|
@@ -31,7 +36,7 @@ export interface StreamEventBackendConfig {
|
|
|
31
36
|
/**
|
|
32
37
|
* CircuitBreaker getter (injected from core)
|
|
33
38
|
*/
|
|
34
|
-
getCircuitBreaker?: (hook: string) =>
|
|
39
|
+
getCircuitBreaker?: (hook: string) => CircuitBreakerLike | undefined;
|
|
35
40
|
}
|
|
36
41
|
/**
|
|
37
42
|
* Event backend implementation using Gravito Stream (Bull Queue).
|
|
@@ -112,3 +117,4 @@ export declare class StreamEventBackend implements EventBackend {
|
|
|
112
117
|
*/
|
|
113
118
|
getDLQHandler(): StreamEventBackendConfig['dlqHandler'] | undefined;
|
|
114
119
|
}
|
|
120
|
+
export {};
|
package/dist/SystemEventJob.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import { Job } from './Job';
|
|
2
|
+
export interface SystemEventJobOptions {
|
|
3
|
+
queue?: string;
|
|
4
|
+
priority?: string | number;
|
|
5
|
+
delay?: number;
|
|
6
|
+
retryAfter?: number;
|
|
7
|
+
retryMultiplier?: number;
|
|
8
|
+
connection?: string;
|
|
9
|
+
}
|
|
2
10
|
/**
|
|
3
11
|
* SystemEventJob - Internal job for processing Gravito async hooks.
|
|
4
12
|
*
|
|
@@ -7,12 +15,12 @@ import { Job } from './Job';
|
|
|
7
15
|
export declare class SystemEventJob extends Job {
|
|
8
16
|
readonly hook: string;
|
|
9
17
|
readonly args: unknown;
|
|
10
|
-
readonly options:
|
|
18
|
+
readonly options: SystemEventJobOptions;
|
|
11
19
|
/**
|
|
12
20
|
* Optional failure callback for DLQ handling.
|
|
13
21
|
*/
|
|
14
22
|
private onFailedCallback?;
|
|
15
|
-
constructor(hook: string, args: unknown, options?:
|
|
23
|
+
constructor(hook: string, args: unknown, options?: SystemEventJobOptions);
|
|
16
24
|
/**
|
|
17
25
|
* Set failure callback for DLQ handling.
|
|
18
26
|
*
|
|
@@ -34,6 +34,7 @@ export declare class StreamingConsumer extends EventEmitter {
|
|
|
34
34
|
private sequencer;
|
|
35
35
|
private heartbeat;
|
|
36
36
|
private abortController;
|
|
37
|
+
private sharedWorker;
|
|
37
38
|
constructor(queueManager: QueueManager, options: ConsumerOptions);
|
|
38
39
|
/**
|
|
39
40
|
* 啟動主消費管線。
|
|
@@ -85,4 +86,5 @@ export declare class StreamingConsumer extends EventEmitter {
|
|
|
85
86
|
* 輸出 debug 日誌(僅在 debug=true 時)。
|
|
86
87
|
*/
|
|
87
88
|
private log;
|
|
89
|
+
private createWorkerForExecution;
|
|
88
90
|
}
|
|
@@ -4,12 +4,12 @@ import type { QueueDriver } from './QueueDriver';
|
|
|
4
4
|
* Bull Queue client interface (compatible with bullmq package).
|
|
5
5
|
*/
|
|
6
6
|
export interface BullQueueClient {
|
|
7
|
-
add(name: string, data:
|
|
8
|
-
getJob(id: string): Promise<
|
|
7
|
+
add(name: string, data: BullJobData, options?: BullJobOptions): Promise<unknown>;
|
|
8
|
+
getJob(id: string): Promise<BullStoredJob | null>;
|
|
9
9
|
count(): Promise<number>;
|
|
10
|
-
process(handler: (job:
|
|
11
|
-
on(event: string, handler: (...args:
|
|
12
|
-
off(event: string, handler: (...args:
|
|
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
13
|
pause(): Promise<void>;
|
|
14
14
|
resume(): Promise<void>;
|
|
15
15
|
clean(grace: number, limit?: number, type?: string): Promise<number>;
|
|
@@ -18,10 +18,60 @@ export interface BullQueueClient {
|
|
|
18
18
|
getDelayedCount(): Promise<number>;
|
|
19
19
|
getFailedCount(): Promise<number>;
|
|
20
20
|
getActiveCount(): Promise<number>;
|
|
21
|
-
[key: string]:
|
|
21
|
+
[key: string]: unknown;
|
|
22
22
|
}
|
|
23
23
|
export interface BullWorkerClient {
|
|
24
|
-
[key: string]:
|
|
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;
|
|
25
75
|
}
|
|
26
76
|
/**
|
|
27
77
|
* Bull Queue driver configuration.
|
|
@@ -43,7 +93,7 @@ export interface BullMQDriverConfig {
|
|
|
43
93
|
port?: number;
|
|
44
94
|
password?: string;
|
|
45
95
|
db?: number;
|
|
46
|
-
[key: string]:
|
|
96
|
+
[key: string]: unknown;
|
|
47
97
|
};
|
|
48
98
|
/**
|
|
49
99
|
* Default number of concurrent workers (default: 1).
|
|
@@ -158,9 +208,9 @@ export declare class BullMQDriver implements QueueDriver {
|
|
|
158
208
|
uptime: number;
|
|
159
209
|
last_ping: string;
|
|
160
210
|
queues: string[];
|
|
161
|
-
metrics?: Record<string,
|
|
162
|
-
[key: string]:
|
|
163
|
-
}, _prefix?: string): Promise<void>;
|
|
211
|
+
metrics?: Record<string, unknown>;
|
|
212
|
+
[key: string]: unknown;
|
|
213
|
+
} & WorkerHeartbeatPayload, _prefix?: string): Promise<void>;
|
|
164
214
|
/**
|
|
165
215
|
* Publishes a log message.
|
|
166
216
|
*/
|
|
@@ -170,8 +220,8 @@ export declare class BullMQDriver implements QueueDriver {
|
|
|
170
220
|
workerId: string;
|
|
171
221
|
jobId?: string;
|
|
172
222
|
timestamp: string;
|
|
173
|
-
[key: string]:
|
|
174
|
-
}, _prefix?: string): Promise<void>;
|
|
223
|
+
[key: string]: unknown;
|
|
224
|
+
} & WorkerLogPayload, _prefix?: string): Promise<void>;
|
|
175
225
|
/**
|
|
176
226
|
* Checks rate limit for a queue.
|
|
177
227
|
*/
|
|
@@ -184,3 +234,4 @@ export declare class BullMQDriver implements QueueDriver {
|
|
|
184
234
|
*/
|
|
185
235
|
getQueues(): Promise<string[]>;
|
|
186
236
|
}
|
|
237
|
+
export {};
|
|
@@ -42,17 +42,7 @@ export interface KafkaDriverConfig {
|
|
|
42
42
|
subscribe: (args: {
|
|
43
43
|
topics: string[];
|
|
44
44
|
}) => Promise<void>;
|
|
45
|
-
run: (args:
|
|
46
|
-
eachMessage: (args: {
|
|
47
|
-
topic: string;
|
|
48
|
-
partition: number;
|
|
49
|
-
message: {
|
|
50
|
-
key?: Buffer;
|
|
51
|
-
value: Buffer;
|
|
52
|
-
offset: string;
|
|
53
|
-
};
|
|
54
|
-
}) => Promise<void>;
|
|
55
|
-
}) => Promise<void>;
|
|
45
|
+
run: (args: KafkaConsumerRunOptions) => Promise<void>;
|
|
56
46
|
disconnect: () => Promise<void>;
|
|
57
47
|
};
|
|
58
48
|
};
|
|
@@ -62,6 +52,28 @@ export interface KafkaDriverConfig {
|
|
|
62
52
|
*/
|
|
63
53
|
consumerGroupId?: string;
|
|
64
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
|
+
}
|
|
65
77
|
/**
|
|
66
78
|
* Kafka-backed queue driver.
|
|
67
79
|
*
|
|
@@ -146,3 +158,4 @@ export declare class KafkaDriver implements QueueDriver {
|
|
|
146
158
|
*/
|
|
147
159
|
subscribe(queue: string, callback: (job: SerializedJob) => Promise<void>): Promise<void>;
|
|
148
160
|
}
|
|
161
|
+
export {};
|
|
@@ -28,6 +28,8 @@ export interface MemoryDriverConfig {
|
|
|
28
28
|
export declare class MemoryDriver implements QueueDriver {
|
|
29
29
|
private queues;
|
|
30
30
|
private maxSize;
|
|
31
|
+
private readonly callbacks;
|
|
32
|
+
private notificationsEnabled;
|
|
31
33
|
constructor(config?: MemoryDriverConfig);
|
|
32
34
|
/**
|
|
33
35
|
* Pushes a job to the in-memory queue.
|
|
@@ -94,15 +96,24 @@ export declare class MemoryDriver implements QueueDriver {
|
|
|
94
96
|
*/
|
|
95
97
|
getQueues(): Promise<string[]>;
|
|
96
98
|
/**
|
|
97
|
-
*
|
|
99
|
+
* Enable notifications for this driver.
|
|
98
100
|
*/
|
|
99
101
|
enableNotifications(): Promise<void>;
|
|
100
102
|
/**
|
|
101
|
-
*
|
|
103
|
+
* Disable notifications for this driver.
|
|
102
104
|
*/
|
|
103
105
|
disableNotifications(): Promise<void>;
|
|
104
106
|
/**
|
|
105
|
-
*
|
|
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.
|
|
106
117
|
*/
|
|
107
|
-
|
|
118
|
+
private notify;
|
|
108
119
|
}
|
|
@@ -148,8 +148,8 @@ export interface QueueDriver {
|
|
|
148
148
|
uptime: number;
|
|
149
149
|
last_ping: string;
|
|
150
150
|
queues: string[];
|
|
151
|
-
metrics?: Record<string,
|
|
152
|
-
[key: string]:
|
|
151
|
+
metrics?: Record<string, unknown>;
|
|
152
|
+
[key: string]: unknown;
|
|
153
153
|
}, prefix?: string): Promise<void>;
|
|
154
154
|
/**
|
|
155
155
|
* Publishes a log entry to the monitoring system.
|
|
@@ -163,7 +163,7 @@ export interface QueueDriver {
|
|
|
163
163
|
workerId: string;
|
|
164
164
|
jobId?: string;
|
|
165
165
|
timestamp: string;
|
|
166
|
-
[key: string]:
|
|
166
|
+
[key: string]: unknown;
|
|
167
167
|
}, prefix?: string): Promise<void>;
|
|
168
168
|
/**
|
|
169
169
|
* Checks if a specific queue has exceeded its rate limit.
|
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
import type { SerializedJob } from '../types';
|
|
2
2
|
import type { QueueDriver } from './QueueDriver';
|
|
3
|
+
interface RabbitMessage {
|
|
4
|
+
content: Buffer;
|
|
5
|
+
}
|
|
6
|
+
interface RabbitChannel {
|
|
7
|
+
assertExchange(exchange: string, type: string, options: {
|
|
8
|
+
durable: boolean;
|
|
9
|
+
}): Promise<unknown>;
|
|
10
|
+
assertQueue(queue: string, options: {
|
|
11
|
+
durable: boolean;
|
|
12
|
+
}): Promise<unknown>;
|
|
13
|
+
bindQueue(queue: string, exchange: string, routingKey: string): Promise<unknown>;
|
|
14
|
+
publish(exchange: string, routingKey: string, content: Buffer, options: {
|
|
15
|
+
persistent: boolean;
|
|
16
|
+
}): boolean;
|
|
17
|
+
sendToQueue(queue: string, content: Buffer, options: {
|
|
18
|
+
persistent: boolean;
|
|
19
|
+
}): boolean;
|
|
20
|
+
get(queue: string, options: {
|
|
21
|
+
noAck: boolean;
|
|
22
|
+
}): Promise<RabbitMessage | false | null>;
|
|
23
|
+
ack(message: RabbitMessage): void;
|
|
24
|
+
nack(message: RabbitMessage, allUpTo: boolean, requeue: boolean): void;
|
|
25
|
+
reject(message: RabbitMessage, requeue: boolean): void;
|
|
26
|
+
consume(queue: string, onMessage: (message: RabbitMessage | null) => Promise<void>, options: {
|
|
27
|
+
noAck: boolean;
|
|
28
|
+
}): Promise<unknown>;
|
|
29
|
+
prefetch(count: number): Promise<unknown>;
|
|
30
|
+
checkQueue(queue: string): Promise<{
|
|
31
|
+
messageCount: number;
|
|
32
|
+
}>;
|
|
33
|
+
purgeQueue(queue: string): Promise<unknown>;
|
|
34
|
+
}
|
|
35
|
+
interface RabbitConnection {
|
|
36
|
+
createChannel(): Promise<RabbitChannel>;
|
|
37
|
+
}
|
|
38
|
+
type RabbitClient = RabbitConnection | RabbitChannel;
|
|
3
39
|
/**
|
|
4
40
|
* RabbitMQ driver configuration.
|
|
5
41
|
*/
|
|
@@ -8,7 +44,7 @@ export interface RabbitMQDriverConfig {
|
|
|
8
44
|
* RabbitMQ client (amqplib) Connection or Channel.
|
|
9
45
|
* If a Connection is provided, the driver will create and manage a Channel.
|
|
10
46
|
*/
|
|
11
|
-
client:
|
|
47
|
+
client: RabbitClient;
|
|
12
48
|
/**
|
|
13
49
|
* Exchange name (optional).
|
|
14
50
|
*/
|
|
@@ -34,18 +70,19 @@ export interface RabbitMQDriverConfig {
|
|
|
34
70
|
*/
|
|
35
71
|
export declare class RabbitMQDriver implements QueueDriver {
|
|
36
72
|
private connection;
|
|
37
|
-
private channel
|
|
73
|
+
private channel?;
|
|
38
74
|
private exchange?;
|
|
39
75
|
private exchangeType;
|
|
40
76
|
constructor(config: RabbitMQDriverConfig);
|
|
77
|
+
private isRabbitConnection;
|
|
41
78
|
/**
|
|
42
79
|
* Ensure channel is created.
|
|
43
80
|
*/
|
|
44
|
-
ensureChannel(): Promise<
|
|
81
|
+
ensureChannel(): Promise<RabbitChannel>;
|
|
45
82
|
/**
|
|
46
83
|
* Get the underlying connection.
|
|
47
84
|
*/
|
|
48
|
-
getRawConnection():
|
|
85
|
+
getRawConnection(): RabbitClient;
|
|
49
86
|
/**
|
|
50
87
|
* Pushes a job to a RabbitMQ queue or exchange.
|
|
51
88
|
*
|
|
@@ -75,11 +112,11 @@ export declare class RabbitMQDriver implements QueueDriver {
|
|
|
75
112
|
/**
|
|
76
113
|
* Negative acknowledge a message.
|
|
77
114
|
*/
|
|
78
|
-
nack(message:
|
|
115
|
+
nack(message: RabbitMessage, requeue?: boolean): Promise<void>;
|
|
79
116
|
/**
|
|
80
117
|
* Reject a message.
|
|
81
118
|
*/
|
|
82
|
-
reject(message:
|
|
119
|
+
reject(message: RabbitMessage, requeue?: boolean): Promise<void>;
|
|
83
120
|
/**
|
|
84
121
|
* Subscribes to a queue.
|
|
85
122
|
*/
|
|
@@ -100,3 +137,4 @@ export declare class RabbitMQDriver implements QueueDriver {
|
|
|
100
137
|
*/
|
|
101
138
|
clear(queue: string): Promise<void>;
|
|
102
139
|
}
|
|
140
|
+
export {};
|
|
@@ -6,26 +6,33 @@ import type { QueueDriver } from './QueueDriver';
|
|
|
6
6
|
export interface RedisClient {
|
|
7
7
|
lpush(key: string, ...values: string[]): Promise<number>;
|
|
8
8
|
rpop(key: string, count?: number): Promise<string | string[] | null>;
|
|
9
|
+
brpop?(...args: Array<string | number>): Promise<[string, string] | null>;
|
|
9
10
|
llen(key: string): Promise<number>;
|
|
10
11
|
del(key: string, ...keys: string[]): Promise<number>;
|
|
11
12
|
lpushx?(key: string, ...values: string[]): Promise<number>;
|
|
12
13
|
rpoplpush?(src: string, dst: string): Promise<string | null>;
|
|
13
14
|
zadd?(key: string, score: number, member: string): Promise<number>;
|
|
15
|
+
zcard?(key: string): Promise<number>;
|
|
14
16
|
zrange?(key: string, start: number, end: number, ...args: string[]): Promise<string[]>;
|
|
17
|
+
zrangebyscore?(key: string, min: string | number, max: string | number): Promise<string[]>;
|
|
15
18
|
zrem?(key: string, ...members: string[]): Promise<number>;
|
|
16
19
|
get?(key: string): Promise<string | null>;
|
|
17
|
-
|
|
20
|
+
hgetall?(key: string): Promise<Record<string, string>>;
|
|
21
|
+
set?(key: string, value: string, ...args: Array<string | number>): Promise<'OK' | null>;
|
|
18
22
|
ltrim?(key: string, start: number, stop: number): Promise<'OK'>;
|
|
19
23
|
lrange?(key: string, start: number, stop: number): Promise<string[]>;
|
|
20
24
|
publish?(channel: string, message: string): Promise<number>;
|
|
21
|
-
pipeline?():
|
|
25
|
+
pipeline?(): RedisPipeline;
|
|
22
26
|
defineCommand?(name: string, options: {
|
|
23
27
|
numberOfKeys: number;
|
|
24
28
|
lua: string;
|
|
25
29
|
}): void;
|
|
26
30
|
incr?(key: string): Promise<number>;
|
|
27
31
|
expire?(key: string, seconds: number): Promise<number>;
|
|
28
|
-
eval(script: string, numKeys: number, ...args: (string | number)[]): Promise<
|
|
32
|
+
eval(script: string, numKeys: number, ...args: (string | number)[]): Promise<unknown>;
|
|
33
|
+
subscribe?(...channels: string[]): Promise<unknown>;
|
|
34
|
+
on?(event: 'message', handler: (channel: string, message: string) => void | Promise<void>): unknown;
|
|
35
|
+
on?(event: string, handler: (...args: unknown[]) => void): unknown;
|
|
29
36
|
/**
|
|
30
37
|
* Binary-capable RPOP(ioredis Buffer mode)
|
|
31
38
|
* 回傳 Buffer 而非 string,支援 binary frame 的零拷貝讀取
|
|
@@ -35,7 +42,7 @@ export interface RedisClient {
|
|
|
35
42
|
* Binary-capable BRPOP(ioredis Buffer mode)
|
|
36
43
|
* 支援 blocking pop 的 binary frame 讀取
|
|
37
44
|
*/
|
|
38
|
-
brpopBuffer?(...args:
|
|
45
|
+
brpopBuffer?(...args: Array<string | number>): Promise<[Buffer, Buffer] | null>;
|
|
39
46
|
/**
|
|
40
47
|
* Binary-capable LRANGE(ioredis Buffer mode)
|
|
41
48
|
* 用於從 DLQ 讀取 binary frame
|
|
@@ -46,7 +53,32 @@ export interface RedisClient {
|
|
|
46
53
|
* 用於將 binary frame 寫入 Redis list
|
|
47
54
|
*/
|
|
48
55
|
lpushBuffer?(key: string, ...values: Buffer[]): Promise<number>;
|
|
49
|
-
[key: string]:
|
|
56
|
+
[key: string]: unknown;
|
|
57
|
+
}
|
|
58
|
+
interface PipelineReply<T = unknown> {
|
|
59
|
+
0: Error | null;
|
|
60
|
+
1: T;
|
|
61
|
+
}
|
|
62
|
+
interface RedisPipeline {
|
|
63
|
+
llen(key: string): RedisPipeline;
|
|
64
|
+
zcard(key: string): RedisPipeline;
|
|
65
|
+
lpush(key: string, ...values: string[]): RedisPipeline;
|
|
66
|
+
ltrim(key: string, start: number, stop: number): RedisPipeline;
|
|
67
|
+
rpop(key: string): RedisPipeline;
|
|
68
|
+
del(key: string, ...keys: string[]): RedisPipeline;
|
|
69
|
+
hset(key: string, values: Record<string, string | number | boolean>): RedisPipeline;
|
|
70
|
+
zadd(key: string, score: number, member: string): RedisPipeline;
|
|
71
|
+
zrem(key: string, ...members: string[]): RedisPipeline;
|
|
72
|
+
pushGroupJob?(waitList: string, activeSet: string, pendingList: string, groupId: string, payload: string): RedisPipeline;
|
|
73
|
+
lpushBuffer?(key: string, ...values: Buffer[]): RedisPipeline;
|
|
74
|
+
exec(): Promise<PipelineReply[] | null>;
|
|
75
|
+
}
|
|
76
|
+
interface WorkerHeartbeatPayload {
|
|
77
|
+
id: string;
|
|
78
|
+
[key: string]: unknown;
|
|
79
|
+
}
|
|
80
|
+
interface LogPayload {
|
|
81
|
+
[key: string]: unknown;
|
|
50
82
|
}
|
|
51
83
|
/**
|
|
52
84
|
* Extended Redis client with custom commands.
|
|
@@ -118,6 +150,7 @@ export declare class RedisDriver implements QueueDriver {
|
|
|
118
150
|
* @returns Buffer(binary path)或 string(legacy path)
|
|
119
151
|
*/
|
|
120
152
|
private serializeJobForTransport;
|
|
153
|
+
private serializeJsonJobForTransport;
|
|
121
154
|
/**
|
|
122
155
|
* 自動偵測並解析 Redis payload 格式
|
|
123
156
|
*
|
|
@@ -228,11 +261,11 @@ export declare class RedisDriver implements QueueDriver {
|
|
|
228
261
|
/**
|
|
229
262
|
* Reports a worker heartbeat.
|
|
230
263
|
*/
|
|
231
|
-
reportHeartbeat(workerInfo:
|
|
264
|
+
reportHeartbeat(workerInfo: WorkerHeartbeatPayload, prefix?: string): Promise<void>;
|
|
232
265
|
/**
|
|
233
266
|
* Publishes monitoring logs.
|
|
234
267
|
*/
|
|
235
|
-
publishLog(logPayload:
|
|
268
|
+
publishLog(logPayload: LogPayload, prefix?: string): Promise<void>;
|
|
236
269
|
/**
|
|
237
270
|
* Checks the rate limit for a queue.
|
|
238
271
|
*/
|
|
@@ -292,3 +325,4 @@ export declare class RedisDriver implements QueueDriver {
|
|
|
292
325
|
*/
|
|
293
326
|
onNotify(queues: string | string[], callback: (queue: string) => Promise<void>): Promise<void>;
|
|
294
327
|
}
|
|
328
|
+
export {};
|
|
@@ -36,6 +36,15 @@ export declare class KafkaNotifier extends EventEmitter {
|
|
|
36
36
|
* @param callback 當訊息到達時呼叫的回呼函式
|
|
37
37
|
*/
|
|
38
38
|
registerCallback(queues: string[], callback: (queue: string) => Promise<void>): void;
|
|
39
|
+
/**
|
|
40
|
+
* 註冊訊息到達事件監聽器。
|
|
41
|
+
*
|
|
42
|
+
* @param callback 當訊息到達時呼叫的回呼函式
|
|
43
|
+
*/
|
|
44
|
+
onMessageArrived(callback: (event: {
|
|
45
|
+
queue: string;
|
|
46
|
+
count: number;
|
|
47
|
+
}) => void): void;
|
|
39
48
|
/**
|
|
40
49
|
* 觸發通知(由 Consumer 的 eachMessage 呼叫)。
|
|
41
50
|
*
|
|
@@ -45,6 +54,13 @@ export declare class KafkaNotifier extends EventEmitter {
|
|
|
45
54
|
* @param queue 佇列名稱
|
|
46
55
|
*/
|
|
47
56
|
notify(queue: string): void;
|
|
57
|
+
/**
|
|
58
|
+
* 觸發帶有數量的通知。
|
|
59
|
+
*
|
|
60
|
+
* @param queue 佇列名稱
|
|
61
|
+
* @param count 訊息數量
|
|
62
|
+
*/
|
|
63
|
+
notifyWithCount(queue: string, count: number): void;
|
|
48
64
|
/**
|
|
49
65
|
* 清除所有已註冊的回呼。
|
|
50
66
|
*
|