@taicode/common-server 1.0.12 → 1.0.14
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/output/index.d.ts +1 -0
- package/output/index.d.ts.map +1 -1
- package/output/index.js +1 -0
- package/output/redis-queue/index.d.ts +2 -1
- package/output/redis-queue/index.d.ts.map +1 -1
- package/output/redis-queue/index.js +1 -1
- package/output/redis-queue/redis-batch-consumer.d.ts +13 -9
- package/output/redis-queue/redis-batch-consumer.d.ts.map +1 -1
- package/output/redis-queue/redis-batch-consumer.js +66 -55
- package/output/redis-queue/redis-batch-consumer.test.d.ts +5 -0
- package/output/redis-queue/redis-batch-consumer.test.d.ts.map +1 -1
- package/output/redis-queue/{batch-consumer.d.ts → redis-queue-batch-consumer.d.ts} +11 -41
- package/output/redis-queue/redis-queue-batch-consumer.d.ts.map +1 -0
- package/output/redis-queue/redis-queue-batch-consumer.js +320 -0
- package/output/redis-queue/redis-queue-batch-consumer.test.d.ts +26 -0
- package/output/redis-queue/redis-queue-batch-consumer.test.d.ts.map +1 -0
- package/output/redis-queue/{batch-consumer.test.js → redis-queue-batch-consumer.test.js} +144 -19
- package/output/redis-queue/redis-queue-common.d.ts +16 -4
- package/output/redis-queue/redis-queue-common.d.ts.map +1 -1
- package/output/redis-queue/redis-queue-common.js +88 -8
- package/output/redis-queue/redis-queue-common.test.d.ts +17 -0
- package/output/redis-queue/redis-queue-common.test.d.ts.map +1 -1
- package/output/redis-queue/redis-queue-common.test.js +27 -65
- package/output/redis-queue/redis-queue-consumer.d.ts +10 -35
- package/output/redis-queue/redis-queue-consumer.d.ts.map +1 -1
- package/output/redis-queue/redis-queue-consumer.js +98 -251
- package/output/redis-queue/redis-queue-consumer.test.d.ts +24 -0
- package/output/redis-queue/redis-queue-consumer.test.d.ts.map +1 -1
- package/output/redis-queue/redis-queue-consumer.test.js +89 -15
- package/output/redis-queue/redis-queue-provider.d.ts +14 -15
- package/output/redis-queue/redis-queue-provider.d.ts.map +1 -1
- package/output/redis-queue/redis-queue-provider.js +16 -13
- package/output/redis-queue/redis-queue-provider.test.d.ts +26 -0
- package/output/redis-queue/redis-queue-provider.test.d.ts.map +1 -1
- package/output/redis-queue/redis-queue-provider.test.js +73 -38
- package/output/redis-queue/test-helpers.d.ts +112 -0
- package/output/redis-queue/test-helpers.d.ts.map +1 -0
- package/output/redis-queue/test-helpers.js +242 -0
- package/output/redis-queue/test-helpers.test.d.ts +28 -0
- package/output/redis-queue/test-helpers.test.d.ts.map +1 -0
- package/output/redis-queue/test-helpers.test.js +572 -0
- package/output/redis-queue/types.d.ts +43 -12
- package/output/redis-queue/types.d.ts.map +1 -1
- package/package.json +5 -3
- package/output/logger/logger.d.ts +0 -33
- package/output/logger/logger.d.ts.map +0 -1
- package/output/logger/logger.js +0 -65
- package/output/logger/logger.test.d.ts +0 -2
- package/output/logger/logger.test.d.ts.map +0 -1
- package/output/logger/logger.test.js +0 -87
- package/output/redis-queue/batch-consumer.d.ts.map +0 -1
- package/output/redis-queue/batch-consumer.js +0 -492
- package/output/redis-queue/batch-consumer.test.d.ts +0 -2
- package/output/redis-queue/batch-consumer.test.d.ts.map +0 -1
- package/output/redis-queue/batch-redis-queue.d.ts +0 -136
- package/output/redis-queue/batch-redis-queue.d.ts.map +0 -1
- package/output/redis-queue/batch-redis-queue.js +0 -583
- package/output/redis-queue/batch-redis-queue.test.d.ts +0 -2
- package/output/redis-queue/batch-redis-queue.test.d.ts.map +0 -1
- package/output/redis-queue/batch-redis-queue.test.js +0 -243
- package/output/redis-queue/redis-queue.d.ts +0 -129
- package/output/redis-queue/redis-queue.d.ts.map +0 -1
- package/output/redis-queue/redis-queue.js +0 -557
- package/output/redis-queue/redis-queue.test.d.ts +0 -2
- package/output/redis-queue/redis-queue.test.d.ts.map +0 -1
- package/output/redis-queue/redis-queue.test.js +0 -234
- package/output/redis-queue/registry.d.ts +0 -57
- package/output/redis-queue/registry.d.ts.map +0 -1
- package/output/redis-queue/registry.js +0 -30
package/output/index.d.ts
CHANGED
package/output/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AACA,cAAc,UAAU,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AACA,cAAc,UAAU,CAAA;AACxB,cAAc,eAAe,CAAA"}
|
package/output/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { RedisQueueProvider } from './redis-queue-provider';
|
|
2
2
|
export { RedisQueueConsumer } from './redis-queue-consumer';
|
|
3
|
-
export {
|
|
3
|
+
export { RedisQueueBatchConsumer } from './redis-queue-batch-consumer';
|
|
4
4
|
export type { RedisQueueProviderConfig, RedisQueueConsumerConfig, BatchConsumerConfig } from './types';
|
|
5
5
|
export type { TaskData } from './types';
|
|
6
|
+
export type { RedisQueueRegistry } from './types';
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/redis-queue/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/redis-queue/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAA;AAGtE,YAAY,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAGtG,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAGvC,YAAY,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { RedisQueueCommon } from './redis-queue-common';
|
|
2
|
-
import type { BatchConsumerConfig,
|
|
2
|
+
import type { BatchConsumerConfig, QueueStats, RedisQueueRegistry } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Redis 批量队列消费者
|
|
5
5
|
*
|
|
6
6
|
* 批量消费任务,每次处理多条
|
|
7
7
|
*
|
|
8
|
-
* @template
|
|
8
|
+
* @template K 队列键名类型
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```ts
|
|
@@ -32,13 +32,13 @@ import type { BatchConsumerConfig, TaskData, QueueStats } from './types';
|
|
|
32
32
|
* consumer.disconnect()
|
|
33
33
|
* ```
|
|
34
34
|
*/
|
|
35
|
-
export declare class RedisBatchConsumer<
|
|
35
|
+
export declare class RedisBatchConsumer<K extends keyof RedisQueueRegistry> extends RedisQueueCommon {
|
|
36
36
|
private consumerRunning;
|
|
37
37
|
private consumerInterval;
|
|
38
38
|
private recoveryInterval;
|
|
39
39
|
private processingBatches;
|
|
40
40
|
private readonly config;
|
|
41
|
-
constructor(config: BatchConsumerConfig<
|
|
41
|
+
constructor(config: BatchConsumerConfig<K>);
|
|
42
42
|
protected getLogPrefix(): string;
|
|
43
43
|
/**
|
|
44
44
|
* 连接 Redis 并自动启动消费者
|
|
@@ -48,11 +48,6 @@ export declare class RedisBatchConsumer<T extends TaskData = TaskData> extends R
|
|
|
48
48
|
* 断开 Redis 连接并停止消费者
|
|
49
49
|
*/
|
|
50
50
|
disconnect(): void;
|
|
51
|
-
/**
|
|
52
|
-
* 恢复超时的任务
|
|
53
|
-
* 检查 processing 队列中的任务,将超时的任务直接标记为失败
|
|
54
|
-
*/
|
|
55
|
-
private recoverStalledTasks;
|
|
56
51
|
/**
|
|
57
52
|
* 批量处理任务
|
|
58
53
|
*/
|
|
@@ -81,5 +76,14 @@ export declare class RedisBatchConsumer<T extends TaskData = TaskData> extends R
|
|
|
81
76
|
* 健康检查
|
|
82
77
|
*/
|
|
83
78
|
health(): Promise<boolean>;
|
|
79
|
+
/**
|
|
80
|
+
* 立即派发批量任务进行处理(仅供测试工具调用)
|
|
81
|
+
*
|
|
82
|
+
* ⚠️ 此方法为 private,仅通过 test-helpers 暴露给测试代码使用
|
|
83
|
+
*
|
|
84
|
+
* @param taskIds 要立即处理的任务 ID 列表
|
|
85
|
+
* @returns Promise,等待所有任务批次处理完成
|
|
86
|
+
*/
|
|
87
|
+
private dispatch;
|
|
84
88
|
}
|
|
85
89
|
//# sourceMappingURL=redis-batch-consumer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis-batch-consumer.d.ts","sourceRoot":"","sources":["../../source/redis-queue/redis-batch-consumer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,KAAK,EAAE,mBAAmB,
|
|
1
|
+
{"version":3,"file":"redis-batch-consumer.d.ts","sourceRoot":"","sources":["../../source/redis-queue/redis-batch-consumer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAA0B,UAAU,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAE1G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,qBAAa,kBAAkB,CAAC,CAAC,SAAS,MAAM,kBAAkB,CAAE,SAAQ,gBAAgB;IAC1F,OAAO,CAAC,eAAe,CAAQ;IAC/B,OAAO,CAAC,gBAAgB,CAA8B;IACtD,OAAO,CAAC,gBAAgB,CAA8B;IACtD,OAAO,CAAC,iBAAiB,CAAI;IAE7B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAOtB;gBAEW,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC;IA2B1C,SAAS,CAAC,YAAY,IAAI,MAAM;IAIhC;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAO9B;;OAEG;IACH,UAAU,IAAI,IAAI;IAMlB;;OAEG;YACW,YAAY;IA4F1B;;OAEG;IACH,OAAO,CAAC,aAAa;IAoBrB;;OAEG;IACH,OAAO,CAAC,YAAY;IAQpB;;OAEG;IACH,OAAO,CAAC,aAAa;IAyErB;;OAEG;IACH,OAAO,CAAC,YAAY;IASpB;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,UAAU,CAAC;IAevC;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC;IAOhC;;;;;;;OAOG;YACW,QAAQ;CA+DvB"}
|
|
@@ -5,7 +5,7 @@ import { RedisQueueCommon } from './redis-queue-common';
|
|
|
5
5
|
*
|
|
6
6
|
* 批量消费任务,每次处理多条
|
|
7
7
|
*
|
|
8
|
-
* @template
|
|
8
|
+
* @template K 队列键名类型
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```ts
|
|
@@ -82,58 +82,6 @@ export class RedisBatchConsumer extends RedisQueueCommon {
|
|
|
82
82
|
this.stopRecovery();
|
|
83
83
|
super.disconnect();
|
|
84
84
|
}
|
|
85
|
-
/**
|
|
86
|
-
* 恢复超时的任务
|
|
87
|
-
* 检查 processing 队列中的任务,将超时的任务直接标记为失败
|
|
88
|
-
*/
|
|
89
|
-
async recoverStalledTasks() {
|
|
90
|
-
if (!this.redis)
|
|
91
|
-
return;
|
|
92
|
-
try {
|
|
93
|
-
const processingTaskIds = await this.redis.lRange(this.processingQueue, 0, -1);
|
|
94
|
-
if (processingTaskIds.length === 0) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
const now = Date.now();
|
|
98
|
-
let recoveredCount = 0;
|
|
99
|
-
for (const taskId of processingTaskIds) {
|
|
100
|
-
const task = await this.getTask(taskId);
|
|
101
|
-
if (!task) {
|
|
102
|
-
// 任务不存在,从队列中移除
|
|
103
|
-
await this.redis.lRem(this.processingQueue, 0, taskId);
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
// 检查是否超时
|
|
107
|
-
const processingTime = now - (task.processingStartTime || now);
|
|
108
|
-
if (processingTime > this.config.processingTimeout) {
|
|
109
|
-
console.log(`[RedisBatchConsumer] Task timeout: ${taskId} (processing time: ${processingTime}ms)`);
|
|
110
|
-
const taskKey = `${this.queueKey}:task:${taskId}`;
|
|
111
|
-
// 超时直接标记为失败
|
|
112
|
-
task.status = 'failed';
|
|
113
|
-
task.processingStartTime = undefined;
|
|
114
|
-
// 使用 Lua 脚本确保原子性
|
|
115
|
-
const script = `
|
|
116
|
-
redis.call('SETEX', KEYS[1], ARGV[1], ARGV[2])
|
|
117
|
-
redis.call('LREM', KEYS[2], 0, ARGV[3])
|
|
118
|
-
redis.call('RPUSH', KEYS[3], ARGV[3])
|
|
119
|
-
return 1
|
|
120
|
-
`;
|
|
121
|
-
await this.redis.eval(script, {
|
|
122
|
-
keys: [taskKey, this.processingQueue, this.failedQueue],
|
|
123
|
-
arguments: [this.cleanupDelay.toString(), JSON.stringify(task), taskId],
|
|
124
|
-
});
|
|
125
|
-
console.error(`[RedisBatchConsumer] Task ${taskId} failed after timeout`);
|
|
126
|
-
recoveredCount++;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
if (recoveredCount > 0) {
|
|
130
|
-
console.log(`[RedisBatchConsumer] Recovered ${recoveredCount} timeout tasks`);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
catch (error) {
|
|
134
|
-
console.error('[RedisBatchConsumer] Failed to recover stalled tasks:', error);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
85
|
/**
|
|
138
86
|
* 批量处理任务
|
|
139
87
|
*/
|
|
@@ -230,12 +178,12 @@ export class RedisBatchConsumer extends RedisQueueCommon {
|
|
|
230
178
|
return;
|
|
231
179
|
}
|
|
232
180
|
// 立即执行一次恢复
|
|
233
|
-
this.
|
|
181
|
+
this.recoverStalled(this.config.processingTimeout).catch(error => {
|
|
234
182
|
console.error('[RedisBatchConsumer] Initial recovery error:', error);
|
|
235
183
|
});
|
|
236
184
|
// 定期检查(每 10 秒检查一次)
|
|
237
185
|
this.recoveryInterval = setInterval(() => {
|
|
238
|
-
this.
|
|
186
|
+
this.recoverStalled(this.config.processingTimeout).catch(error => {
|
|
239
187
|
console.error('[RedisBatchConsumer] Recovery error:', error);
|
|
240
188
|
});
|
|
241
189
|
}, 10000);
|
|
@@ -357,4 +305,67 @@ export class RedisBatchConsumer extends RedisQueueCommon {
|
|
|
357
305
|
const result = await catchIt(() => this.redis.ping());
|
|
358
306
|
return !result.isError() && result.value === 'PONG';
|
|
359
307
|
}
|
|
308
|
+
/**
|
|
309
|
+
* 立即派发批量任务进行处理(仅供测试工具调用)
|
|
310
|
+
*
|
|
311
|
+
* ⚠️ 此方法为 private,仅通过 test-helpers 暴露给测试代码使用
|
|
312
|
+
*
|
|
313
|
+
* @param taskIds 要立即处理的任务 ID 列表
|
|
314
|
+
* @returns Promise,等待所有任务批次处理完成
|
|
315
|
+
*/
|
|
316
|
+
async dispatch(taskIds) {
|
|
317
|
+
if (!this.redis || !this.redis.isOpen) {
|
|
318
|
+
throw new Error('[RedisBatchConsumer] Redis is not connected');
|
|
319
|
+
}
|
|
320
|
+
if (taskIds.length === 0) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
// 使用 Lua 脚本将任务从 pending 移到 processing(忽略延迟时间)
|
|
324
|
+
const moveToProcessingScript = `
|
|
325
|
+
local pendingQueue = KEYS[1]
|
|
326
|
+
local processingQueue = KEYS[2]
|
|
327
|
+
local movedIds = {}
|
|
328
|
+
|
|
329
|
+
-- ARGV[1], ARGV[2], ... 是 taskId
|
|
330
|
+
for i = 1, #ARGV do
|
|
331
|
+
local taskId = ARGV[i]
|
|
332
|
+
local removed = redis.call('LREM', pendingQueue, 0, taskId)
|
|
333
|
+
if removed > 0 then
|
|
334
|
+
redis.call('RPUSH', processingQueue, taskId)
|
|
335
|
+
table.insert(movedIds, taskId)
|
|
336
|
+
end
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
return movedIds
|
|
340
|
+
`;
|
|
341
|
+
const movedIds = await this.redis.eval(moveToProcessingScript, {
|
|
342
|
+
keys: [this.pendingQueue, this.processingQueue],
|
|
343
|
+
arguments: taskIds,
|
|
344
|
+
});
|
|
345
|
+
if (movedIds.length === 0) {
|
|
346
|
+
console.warn('[RedisBatchConsumer] No tasks were moved to processing queue');
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
// 按照 batchSize 分批处理并等待完成
|
|
350
|
+
const batches = [];
|
|
351
|
+
for (let i = 0; i < movedIds.length; i += this.config.batchSize) {
|
|
352
|
+
batches.push(movedIds.slice(i, i + this.config.batchSize));
|
|
353
|
+
}
|
|
354
|
+
// 串行处理每个批次(遵循批量消费语义)
|
|
355
|
+
for (const batch of batches) {
|
|
356
|
+
await this.processBatch(batch);
|
|
357
|
+
}
|
|
358
|
+
// 检查是否有任务需要重试(已放回 pending 队列)
|
|
359
|
+
const retryIds = [];
|
|
360
|
+
for (const taskId of movedIds) {
|
|
361
|
+
const task = await this.getTask(taskId);
|
|
362
|
+
if (task && task.status === 'pending' && task.retryCount > 0) {
|
|
363
|
+
retryIds.push(taskId);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
// 递归处理重试任务
|
|
367
|
+
if (retryIds.length > 0) {
|
|
368
|
+
await this.dispatch(retryIds);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
360
371
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis-batch-consumer.test.d.ts","sourceRoot":"","sources":["../../source/redis-queue/redis-batch-consumer.test.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"redis-batch-consumer.test.d.ts","sourceRoot":"","sources":["../../source/redis-queue/redis-batch-consumer.test.ts"],"names":[],"mappings":"AAOA,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAU,kBAAkB;QAC1B,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAClC;CACF"}
|
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { RedisQueueCommon } from './redis-queue-common';
|
|
2
|
+
import type { BatchConsumerConfig, QueueStats, RedisQueueRegistry } from './types';
|
|
2
3
|
/**
|
|
3
4
|
* Redis 批量队列消费者
|
|
4
5
|
*
|
|
5
6
|
* 批量消费任务,每次处理多条
|
|
6
7
|
*
|
|
7
|
-
* @template
|
|
8
|
+
* @template K 队列键名类型
|
|
8
9
|
*
|
|
9
10
|
* @example
|
|
10
11
|
* ```ts
|
|
11
|
-
*
|
|
12
|
-
* to: string
|
|
13
|
-
* }
|
|
14
|
-
*
|
|
15
|
-
* const consumer = new RedisBatchConsumer<EmailTask>({
|
|
12
|
+
* const consumer = new RedisQueueBatchConsumer('email-queue', {
|
|
16
13
|
* redisUrl: 'redis://localhost:6379',
|
|
17
|
-
* queueKey: 'email-queue',
|
|
18
14
|
* batchSize: 50,
|
|
19
15
|
* handler: async (dataList) => {
|
|
20
16
|
* await sendEmailsBatch(dataList.map(d => d.to))
|
|
@@ -31,46 +27,24 @@ import type { BatchConsumerConfig, TaskData, QueueStats } from './types';
|
|
|
31
27
|
* consumer.disconnect()
|
|
32
28
|
* ```
|
|
33
29
|
*/
|
|
34
|
-
export declare class
|
|
30
|
+
export declare class RedisQueueBatchConsumer<K extends keyof RedisQueueRegistry> extends RedisQueueCommon {
|
|
35
31
|
private consumerRunning;
|
|
36
|
-
private redis;
|
|
37
32
|
private consumerInterval;
|
|
38
33
|
private recoveryInterval;
|
|
39
34
|
private processingBatches;
|
|
35
|
+
private processingPromises;
|
|
40
36
|
private readonly config;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
private readonly processingQueue;
|
|
44
|
-
private readonly completedQueue;
|
|
45
|
-
constructor(config: BatchConsumerConfig<T>);
|
|
37
|
+
constructor(queueKey: K, config: BatchConsumerConfig<K>);
|
|
38
|
+
protected getLogPrefix(): string;
|
|
46
39
|
/**
|
|
47
40
|
* 连接 Redis 并自动启动消费者
|
|
48
41
|
*/
|
|
49
42
|
connect(): Promise<void>;
|
|
50
43
|
/**
|
|
51
44
|
* 断开 Redis 连接并停止消费者
|
|
45
|
+
* 会等待所有正在处理的批次完成后再断开连接
|
|
52
46
|
*/
|
|
53
|
-
disconnect(): void
|
|
54
|
-
/**
|
|
55
|
-
* 获取任务详情
|
|
56
|
-
*/
|
|
57
|
-
private getTask;
|
|
58
|
-
/**
|
|
59
|
-
* 更新任务状态并移动到对应队列(原子操作)
|
|
60
|
-
*/
|
|
61
|
-
private applyStatus;
|
|
62
|
-
/**
|
|
63
|
-
* 批量更新任务状态
|
|
64
|
-
*/
|
|
65
|
-
private applyStatusBatch;
|
|
66
|
-
/**
|
|
67
|
-
* 根据状态获取对应的队列键
|
|
68
|
-
*/
|
|
69
|
-
private getQueueByStatus;
|
|
70
|
-
/**
|
|
71
|
-
* 恢复超时的任务
|
|
72
|
-
*/
|
|
73
|
-
private recoverStalledTasks;
|
|
47
|
+
disconnect(): Promise<void>;
|
|
74
48
|
/**
|
|
75
49
|
* 批量处理任务
|
|
76
50
|
*/
|
|
@@ -95,13 +69,9 @@ export declare class RedisBatchConsumer<T extends TaskData = TaskData> {
|
|
|
95
69
|
* 获取队列统计信息(O(1) 时间复杂度)
|
|
96
70
|
*/
|
|
97
71
|
statistics(): Promise<QueueStats>;
|
|
98
|
-
/**
|
|
99
|
-
* 清空所有队列和任务数据
|
|
100
|
-
*/
|
|
101
|
-
clear(): Promise<void>;
|
|
102
72
|
/**
|
|
103
73
|
* 健康检查
|
|
104
74
|
*/
|
|
105
75
|
health(): Promise<boolean>;
|
|
106
76
|
}
|
|
107
|
-
//# sourceMappingURL=batch-consumer.d.ts.map
|
|
77
|
+
//# sourceMappingURL=redis-queue-batch-consumer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis-queue-batch-consumer.d.ts","sourceRoot":"","sources":["../../source/redis-queue/redis-queue-batch-consumer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAA0B,UAAU,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAE1G;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,uBAAuB,CAAC,CAAC,SAAS,MAAM,kBAAkB,CAAE,SAAQ,gBAAgB;IAC/F,OAAO,CAAC,eAAe,CAAQ;IAC/B,OAAO,CAAC,gBAAgB,CAA8B;IACtD,OAAO,CAAC,gBAAgB,CAA8B;IACtD,OAAO,CAAC,iBAAiB,CAAI;IAC7B,OAAO,CAAC,kBAAkB,CAA2B;IAErD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAOtB;gBAEW,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC;IAuBvD,SAAS,CAAC,YAAY,IAAI,MAAM;IAIhC;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAO9B;;;OAGG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAgBjC;;OAEG;YACW,YAAY;IA2G1B;;OAEG;IACH,OAAO,CAAC,aAAa;IAoBrB;;OAEG;IACH,OAAO,CAAC,YAAY;IAQpB;;OAEG;IACH,OAAO,CAAC,aAAa;IAyErB;;OAEG;IACH,OAAO,CAAC,YAAY;IASpB;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,UAAU,CAAC;IAevC;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC;CAMjC"}
|