@taicode/common-server 3.0.1 → 3.2.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.
- package/output/context/index.d.ts +6 -0
- package/output/context/index.d.ts.map +1 -0
- package/output/context/index.js +14 -0
- package/output/context/index.test.d.ts +2 -0
- package/output/context/index.test.d.ts.map +1 -0
- package/output/context/index.test.js +14 -0
- package/output/index.d.ts +4 -2
- package/output/index.d.ts.map +1 -1
- package/output/index.js +4 -2
- package/output/rate-limiter/index.d.ts +4 -0
- package/output/rate-limiter/index.d.ts.map +1 -0
- package/output/rate-limiter/index.js +3 -0
- package/output/rate-limiter/memory-store.d.ts +12 -0
- package/output/rate-limiter/memory-store.d.ts.map +1 -0
- package/output/rate-limiter/memory-store.js +46 -0
- package/output/rate-limiter/rate-limiter.d.ts +17 -0
- package/output/rate-limiter/rate-limiter.d.ts.map +1 -0
- package/output/rate-limiter/rate-limiter.js +64 -0
- package/output/rate-limiter/types.d.ts +27 -0
- package/output/rate-limiter/types.d.ts.map +1 -0
- package/output/rate-limiter/types.js +1 -0
- package/output/redis-queue/index.d.ts +7 -7
- package/output/redis-queue/index.d.ts.map +1 -1
- package/output/redis-queue/index.js +4 -4
- package/output/redis-queue/redis-queue-batch-consumer.d.ts +3 -3
- package/output/redis-queue/redis-queue-batch-consumer.d.ts.map +1 -1
- package/output/redis-queue/redis-queue-batch-consumer.js +19 -18
- package/output/redis-queue/redis-queue-batch-consumer.test.d.ts +1 -1
- package/output/redis-queue/redis-queue-batch-consumer.test.d.ts.map +1 -1
- package/output/redis-queue/redis-queue-batch-consumer.test.js +3 -3
- package/output/redis-queue/redis-queue-common.d.ts +2 -2
- package/output/redis-queue/redis-queue-common.d.ts.map +1 -1
- package/output/redis-queue/redis-queue-common.js +5 -4
- package/output/redis-queue/redis-queue-common.test.d.ts +1 -1
- package/output/redis-queue/redis-queue-common.test.d.ts.map +1 -1
- package/output/redis-queue/redis-queue-common.test.js +1 -1
- package/output/redis-queue/redis-queue-consumer.d.ts +3 -3
- package/output/redis-queue/redis-queue-consumer.d.ts.map +1 -1
- package/output/redis-queue/redis-queue-consumer.js +19 -18
- package/output/redis-queue/redis-queue-consumer.test.d.ts +1 -1
- package/output/redis-queue/redis-queue-consumer.test.d.ts.map +1 -1
- package/output/redis-queue/redis-queue-consumer.test.js +3 -3
- package/output/redis-queue/redis-queue-provider.d.ts +2 -2
- package/output/redis-queue/redis-queue-provider.d.ts.map +1 -1
- package/output/redis-queue/redis-queue-provider.js +6 -5
- package/output/redis-queue/redis-queue-provider.test.d.ts +1 -1
- package/output/redis-queue/redis-queue-provider.test.d.ts.map +1 -1
- package/output/redis-queue/redis-queue-provider.test.js +2 -2
- package/output/redis-queue/test-helpers.d.ts +4 -4
- package/output/redis-queue/test-helpers.d.ts.map +1 -1
- package/output/redis-queue/test-helpers.js +1 -1
- package/output/redis-queue/test-helpers.test.d.ts +1 -1
- package/output/redis-queue/test-helpers.test.d.ts.map +1 -1
- package/output/redis-queue/test-helpers.test.js +4 -4
- package/output/redis-queue/types.d.ts +1 -1
- package/output/redis-queue/types.d.ts.map +1 -1
- package/output/schema/index.d.ts +1 -1
- package/output/schema/index.d.ts.map +1 -1
- package/output/schema/index.js +1 -1
- package/package.json +15 -13
- package/output/redis-queue/redis-batch-consumer.d.ts +0 -89
- package/output/redis-queue/redis-batch-consumer.d.ts.map +0 -1
- package/output/redis-queue/redis-batch-consumer.js +0 -371
- package/output/redis-queue/redis-batch-consumer.test.d.ts +0 -7
- package/output/redis-queue/redis-batch-consumer.test.d.ts.map +0 -1
- package/output/redis-queue/redis-batch-consumer.test.js +0 -265
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { catchIt } from '@taicode/common-base';
|
|
2
|
-
import {
|
|
2
|
+
import { logger } from '@taicode/common-base';
|
|
3
|
+
import { RedisQueueCommon } from './redis-queue-common.js';
|
|
3
4
|
/**
|
|
4
5
|
* Redis 队列消费者
|
|
5
6
|
*
|
|
@@ -30,7 +31,7 @@ import { RedisQueueCommon } from './redis-queue-common';
|
|
|
30
31
|
* {
|
|
31
32
|
* redisUrl: 'redis://localhost:6379',
|
|
32
33
|
* handler: async (data) => {
|
|
33
|
-
*
|
|
34
|
+
* logger.info(data.orderId, data.amount)
|
|
34
35
|
* return catchIt(() => {})
|
|
35
36
|
* }
|
|
36
37
|
* }
|
|
@@ -94,9 +95,9 @@ export class RedisQueueConsumer extends RedisQueueCommon {
|
|
|
94
95
|
this.stopRecovery();
|
|
95
96
|
// 等待所有正在处理的任务完成
|
|
96
97
|
if (this.processingPromises.size > 0) {
|
|
97
|
-
|
|
98
|
+
logger.info(`[RedisQueueConsumer] Waiting for ${this.processingPromises.size} tasks to complete...`);
|
|
98
99
|
await Promise.allSettled(this.processingPromises);
|
|
99
|
-
|
|
100
|
+
logger.info(`[RedisQueueConsumer] All tasks completed`);
|
|
100
101
|
}
|
|
101
102
|
// 最后断开 Redis 连接
|
|
102
103
|
super.disconnect();
|
|
@@ -111,12 +112,12 @@ export class RedisQueueConsumer extends RedisQueueCommon {
|
|
|
111
112
|
try {
|
|
112
113
|
const task = await this.getTask(taskId);
|
|
113
114
|
if (!task) {
|
|
114
|
-
|
|
115
|
+
logger.warn(`[RedisQueueConsumer] Task not found: ${taskId}`);
|
|
115
116
|
return;
|
|
116
117
|
}
|
|
117
118
|
// 任务应该是 pending 状态(Lua 脚本已确保延迟检查)
|
|
118
119
|
if (task.status !== 'pending') {
|
|
119
|
-
|
|
120
|
+
logger.info(`[RedisQueueConsumer] Task ${taskId} has invalid status (${task.status}), marking as failed`);
|
|
120
121
|
await this.applyStatus(taskId, task.status, 'failed');
|
|
121
122
|
return;
|
|
122
123
|
}
|
|
@@ -130,10 +131,10 @@ export class RedisQueueConsumer extends RedisQueueCommon {
|
|
|
130
131
|
await this.config.handler(task.data);
|
|
131
132
|
// 更新状态为完成
|
|
132
133
|
await this.applyStatus(taskId, 'processing', 'completed');
|
|
133
|
-
|
|
134
|
+
logger.info(`[RedisQueueConsumer] Task completed: ${taskId}`);
|
|
134
135
|
}
|
|
135
136
|
catch (error) {
|
|
136
|
-
|
|
137
|
+
logger.error(`[RedisQueueConsumer] Task failed: ${taskId}`, error);
|
|
137
138
|
// 检查是否需要重试
|
|
138
139
|
if (task.retryCount < task.maxRetries) {
|
|
139
140
|
task.retryCount++;
|
|
@@ -151,7 +152,7 @@ export class RedisQueueConsumer extends RedisQueueCommon {
|
|
|
151
152
|
keys: [taskKey, this.processingQueue, this.pendingQueue],
|
|
152
153
|
arguments: [this.config.cleanupDelay.toString(), JSON.stringify(task), taskId],
|
|
153
154
|
});
|
|
154
|
-
|
|
155
|
+
logger.info(`[RedisQueueConsumer] Task ${taskId} will retry (${task.retryCount}/${task.maxRetries})`);
|
|
155
156
|
}
|
|
156
157
|
else {
|
|
157
158
|
task.status = 'failed';
|
|
@@ -168,7 +169,7 @@ export class RedisQueueConsumer extends RedisQueueCommon {
|
|
|
168
169
|
keys: [taskKey, this.processingQueue, this.failedQueue],
|
|
169
170
|
arguments: [this.config.cleanupDelay.toString(), JSON.stringify(task), taskId],
|
|
170
171
|
});
|
|
171
|
-
|
|
172
|
+
logger.error(`[RedisQueueConsumer] Task ${taskId} failed after ${task.maxRetries} retries`);
|
|
172
173
|
}
|
|
173
174
|
}
|
|
174
175
|
}
|
|
@@ -194,15 +195,15 @@ export class RedisQueueConsumer extends RedisQueueCommon {
|
|
|
194
195
|
}
|
|
195
196
|
// 立即执行一次恢复
|
|
196
197
|
this.recoverStalled(this.config.processingTimeout).catch(error => {
|
|
197
|
-
|
|
198
|
+
logger.error('[RedisQueueConsumer] Initial recovery error:', error);
|
|
198
199
|
});
|
|
199
200
|
// 定期检查(每 10 秒检查一次)
|
|
200
201
|
this.recoveryInterval = setInterval(() => {
|
|
201
202
|
this.recoverStalled(this.config.processingTimeout).catch(error => {
|
|
202
|
-
|
|
203
|
+
logger.error('[RedisQueueConsumer] Recovery error:', error);
|
|
203
204
|
});
|
|
204
205
|
}, 10000);
|
|
205
|
-
|
|
206
|
+
logger.info('[RedisQueueConsumer] Recovery mechanism started');
|
|
206
207
|
}
|
|
207
208
|
/**
|
|
208
209
|
* 停止恢复机制(内部方法,自动调用)
|
|
@@ -211,7 +212,7 @@ export class RedisQueueConsumer extends RedisQueueCommon {
|
|
|
211
212
|
if (this.recoveryInterval) {
|
|
212
213
|
clearInterval(this.recoveryInterval);
|
|
213
214
|
this.recoveryInterval = null;
|
|
214
|
-
|
|
215
|
+
logger.info('[RedisQueueConsumer] Recovery mechanism stopped');
|
|
215
216
|
}
|
|
216
217
|
}
|
|
217
218
|
/**
|
|
@@ -222,7 +223,7 @@ export class RedisQueueConsumer extends RedisQueueCommon {
|
|
|
222
223
|
return;
|
|
223
224
|
}
|
|
224
225
|
this.consumerRunning = true;
|
|
225
|
-
|
|
226
|
+
logger.info(`[RedisQueueConsumer] Consumer started with concurrency: ${this.config.concurrency}`);
|
|
226
227
|
// Lua 脚本: 原子化从 pending 取出任务并移到 processing(只取已到延迟时间的任务)
|
|
227
228
|
const popAndMoveScript = `
|
|
228
229
|
local pendingQueue = KEYS[1]
|
|
@@ -279,12 +280,12 @@ export class RedisQueueConsumer extends RedisQueueCommon {
|
|
|
279
280
|
// 并发处理所有任务(不等待完成)
|
|
280
281
|
taskIds.forEach(taskId => {
|
|
281
282
|
this.processTask(taskId).catch(error => {
|
|
282
|
-
|
|
283
|
+
logger.error(`[RedisQueueConsumer] Unhandled error in processTask: ${taskId}`, error);
|
|
283
284
|
});
|
|
284
285
|
});
|
|
285
286
|
}
|
|
286
287
|
catch (error) {
|
|
287
|
-
|
|
288
|
+
logger.error('[RedisQueueConsumer] Consumer error:', error);
|
|
288
289
|
}
|
|
289
290
|
}, this.config.consumerInterval);
|
|
290
291
|
}
|
|
@@ -297,7 +298,7 @@ export class RedisQueueConsumer extends RedisQueueCommon {
|
|
|
297
298
|
this.consumerInterval = null;
|
|
298
299
|
}
|
|
299
300
|
this.consumerRunning = false;
|
|
300
|
-
|
|
301
|
+
logger.info('[RedisQueueConsumer] Consumer stopped');
|
|
301
302
|
}
|
|
302
303
|
/**
|
|
303
304
|
* 获取队列统计信息(O(1) 时间复杂度)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis-queue-consumer.test.d.ts","sourceRoot":"","sources":["../../source/redis-queue/redis-queue-consumer.test.ts"],"names":[],"mappings":"AAQA,KAAK,YAAY,GAAG;IAClB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACvB,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IACvB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,MAAM,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,GAAG,CAAA;CACX,CAAA;AAGD,OAAO,QAAQ,
|
|
1
|
+
{"version":3,"file":"redis-queue-consumer.test.d.ts","sourceRoot":"","sources":["../../source/redis-queue/redis-queue-consumer.test.ts"],"names":[],"mappings":"AAQA,KAAK,YAAY,GAAG;IAClB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACvB,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IACvB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,MAAM,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,GAAG,CAAA;CACX,CAAA;AAGD,OAAO,QAAQ,YAAY,CAAC;IAC1B,UAAU,kBAAkB;QAC1B,CAAC,GAAG,EAAE,cAAc,MAAM,EAAE,GAAG,YAAY,CAAA;KAC5C;CACF"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { describe, it, expect, afterEach } from 'vitest';
|
|
2
2
|
import { catchIt } from '@taicode/common-base';
|
|
3
|
-
import { RedisQueueProvider } from './redis-queue-provider';
|
|
4
|
-
import { RedisQueueConsumer } from './redis-queue-consumer';
|
|
5
|
-
import { dispatchQueueTask, waitQueueCompletion, clearQueue, getQueueTasks } from './test-helpers';
|
|
3
|
+
import { RedisQueueProvider } from './redis-queue-provider.js';
|
|
4
|
+
import { RedisQueueConsumer } from './redis-queue-consumer.js';
|
|
5
|
+
import { dispatchQueueTask, waitQueueCompletion, clearQueue, getQueueTasks } from './test-helpers.js';
|
|
6
6
|
const REDIS_URL = process.env.REDIS_URL || 'redis://localhost:6379';
|
|
7
7
|
describe('RedisQueueConsumer', () => {
|
|
8
8
|
const providers = [];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RedisQueueCommon } from './redis-queue-common';
|
|
2
|
-
import type { RedisQueueRegistry, RedisQueueProviderConfig, Task, QueueStats } from './types';
|
|
1
|
+
import { RedisQueueCommon } from './redis-queue-common.js';
|
|
2
|
+
import type { RedisQueueRegistry, RedisQueueProviderConfig, Task, QueueStats } from './types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Redis 队列生产者
|
|
5
5
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis-queue-provider.d.ts","sourceRoot":"","sources":["../../source/redis-queue/redis-queue-provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"redis-queue-provider.d.ts","sourceRoot":"","sources":["../../source/redis-queue/redis-queue-provider.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEhG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,qBAAa,kBAAkB,CAC7B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,kBAAkB,EAClD,CAAC,SAAS,MAAM,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC,GAAG,MAAM,CAC7C,SAAQ,gBAAgB;IACxB,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAQ;gBAE5B,QAAQ,EAAE,CAAC,EAAE,MAAM,GAAE,wBAA6B;IAU9D,SAAS,CAAC,YAAY,IAAI,MAAM;IAMhC;;;;;;;;;;;OAWG;IACG,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IACxC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IA0F1C;;OAEG;IACG,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAWzD;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,UAAU,CAAC;IAevC;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAmD7B"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import {
|
|
2
|
+
import { logger } from '@taicode/common-base';
|
|
3
|
+
import { RedisQueueCommon } from './redis-queue-common.js';
|
|
3
4
|
/**
|
|
4
5
|
* Redis 队列生产者
|
|
5
6
|
*
|
|
@@ -49,7 +50,7 @@ export class RedisQueueProvider extends RedisQueueCommon {
|
|
|
49
50
|
}
|
|
50
51
|
async enqueue(data) {
|
|
51
52
|
if (!this.redis) {
|
|
52
|
-
|
|
53
|
+
logger.warn('[RedisQueueProvider] Redis not available, skipping task enqueue');
|
|
53
54
|
return Array.isArray(data) ? [] : '';
|
|
54
55
|
}
|
|
55
56
|
// 统一处理为数组
|
|
@@ -114,10 +115,10 @@ export class RedisQueueProvider extends RedisQueueCommon {
|
|
|
114
115
|
arguments: args,
|
|
115
116
|
});
|
|
116
117
|
if (successCount < tasks.length) {
|
|
117
|
-
|
|
118
|
+
logger.info(`[RedisQueueProvider] ${tasks.length - successCount} tasks already exist, skipped`);
|
|
118
119
|
}
|
|
119
120
|
if (successCount > 0) {
|
|
120
|
-
|
|
121
|
+
logger.info(`[RedisQueueProvider] Enqueued ${successCount} tasks`);
|
|
121
122
|
}
|
|
122
123
|
// 返回单个 ID 或 ID 数组
|
|
123
124
|
return Array.isArray(data) ? taskIds : taskIds[0];
|
|
@@ -198,7 +199,7 @@ export class RedisQueueProvider extends RedisQueueCommon {
|
|
|
198
199
|
arguments: [this.queueKey],
|
|
199
200
|
});
|
|
200
201
|
if (deletedCount > 0) {
|
|
201
|
-
|
|
202
|
+
logger.info(`[RedisQueueProvider] Cleared ${deletedCount} tasks`);
|
|
202
203
|
}
|
|
203
204
|
}
|
|
204
205
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis-queue-provider.test.d.ts","sourceRoot":"","sources":["../../source/redis-queue/redis-queue-provider.test.ts"],"names":[],"mappings":"AAMA,KAAK,YAAY,GAAG;IAClB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACvB,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IACvB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,MAAM,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,GAAG,CAAA;CACX,CAAA;AAGD,OAAO,QAAQ,
|
|
1
|
+
{"version":3,"file":"redis-queue-provider.test.d.ts","sourceRoot":"","sources":["../../source/redis-queue/redis-queue-provider.test.ts"],"names":[],"mappings":"AAMA,KAAK,YAAY,GAAG;IAClB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACvB,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IACvB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,MAAM,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,GAAG,CAAA;CACX,CAAA;AAGD,OAAO,QAAQ,YAAY,CAAC;IAC1B,UAAU,kBAAkB;QAC1B,CAAC,GAAG,EAAE,iBAAiB,MAAM,EAAE,GAAG,YAAY,CAAA;KAC/C;CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, it, expect, afterEach } from "vitest";
|
|
2
|
-
import { RedisQueueProvider } from "./redis-queue-provider";
|
|
3
|
-
import { clearQueue, getQueueTasks } from "./test-helpers";
|
|
2
|
+
import { RedisQueueProvider } from "./redis-queue-provider.js";
|
|
3
|
+
import { clearQueue, getQueueTasks } from "./test-helpers.js";
|
|
4
4
|
const REDIS_URL = process.env.REDIS_URL || "redis://localhost:6379";
|
|
5
5
|
describe("RedisQueueProvider", () => {
|
|
6
6
|
const providers = [];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { RedisQueueBatchConsumer } from './redis-queue-batch-consumer';
|
|
2
|
-
import { RedisQueueConsumer } from './redis-queue-consumer';
|
|
3
|
-
import type { RedisQueueProvider } from './redis-queue-provider';
|
|
4
|
-
import type { RedisQueueRegistry, Task } from './types';
|
|
1
|
+
import type { RedisQueueBatchConsumer } from './redis-queue-batch-consumer.js';
|
|
2
|
+
import { RedisQueueConsumer } from './redis-queue-consumer.js';
|
|
3
|
+
import type { RedisQueueProvider } from './redis-queue-provider.js';
|
|
4
|
+
import type { RedisQueueRegistry, Task } from './types.js';
|
|
5
5
|
/**
|
|
6
6
|
* 测试辅助函数:立即派发任务到消费者
|
|
7
7
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-helpers.d.ts","sourceRoot":"","sources":["../../source/redis-queue/test-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"test-helpers.d.ts","sourceRoot":"","sources":["../../source/redis-queue/test-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAA;AAC9E,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AACnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAsB,iBAAiB,CACrC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,kBAAkB,EAClD,CAAC,SAAS,MAAM,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC,GAAG,MAAM,EAE7C,QAAQ,EAAE,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,uBAAuB,CAAC,CAAC,EAAE,CAAC,CAAC,EAClE,OAAO,EAAE,MAAM,EAAE,GAChB,OAAO,CAAC,IAAI,CAAC,CA+Ff;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,mBAAmB,CACvC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,kBAAkB,EAClD,CAAC,SAAS,MAAM,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC,GAAG,MAAM,EAE7C,QAAQ,EAAE,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,uBAAuB,CAAC,CAAC,EAAE,CAAC,CAAC,EAC7F,SAAS,EAA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AE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,GAAG,CAAA;IACV,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAGD,OAAO,QAAQ,YAAY,CAAC;IAC1B,UAAU,kBAAkB;QAC1B,CAAC,GAAG,EAAE,QAAQ,MAAM,EAAE,GAAG,YAAY,CAAA;KACtC;CACF"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
2
|
import { catchIt } from '@taicode/common-base';
|
|
3
|
-
import { RedisQueueProvider } from './redis-queue-provider';
|
|
4
|
-
import { RedisQueueConsumer } from './redis-queue-consumer';
|
|
5
|
-
import { RedisQueueBatchConsumer } from './redis-queue-batch-consumer';
|
|
6
|
-
import { dispatchQueueTask, waitQueueCompletion, clearQueue, getQueueTasks, } from './test-helpers';
|
|
3
|
+
import { RedisQueueProvider } from './redis-queue-provider.js';
|
|
4
|
+
import { RedisQueueConsumer } from './redis-queue-consumer.js';
|
|
5
|
+
import { RedisQueueBatchConsumer } from './redis-queue-batch-consumer.js';
|
|
6
|
+
import { dispatchQueueTask, waitQueueCompletion, clearQueue, getQueueTasks, } from './test-helpers.js';
|
|
7
7
|
const REDIS_URL = process.env.REDIS_URL || 'redis://localhost:6379';
|
|
8
8
|
/**
|
|
9
9
|
* 测试辅助方法使用示例
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../source/redis-queue/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../source/redis-queue/types.ts"],"names":[],"mappings":"AAAA,OAAO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ANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/schema/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/schema/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5C,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AA2BzC;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,SAAS,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;;;;;;;;;;;;;kBAMlF;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,EAAE,CAAC;;;kBAKxD;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,kCAE/B;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,EAAE,CAAC;;;kBAKvD;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,SAAS,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;;;;;;;;;;kBAMvF;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,EAAE,CAAC;;;mBAK7D;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,EAAE,CAAC;;;;;;;;;;;kBAMjE;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,EAAE,CAAC;;;mBAKjE;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,SAAS,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;;;;;;;;;;;;;kBAMtF;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,EAAE,CAAC;;;kBAK5D;AAGD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,SAAS,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;;;;kBAMlF;AAED,wBAAgB,cAAc,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,SAAS,OAAO,EAAE,CAAC,SAAS,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;;;;;;;;;;;;;;;;;;EAMvG;AAED,UAAU,YAAa,SAAQ,aAAa;IAC1C,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS,YAAY,EAAE,MAAM,EAAE,CAAC,GAAG,YAAY,GAAG,CAAC,GAAG,YAAY,CAY/F"}
|
package/output/schema/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,43 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taicode/common-server",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"author": "Alain",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"description": "",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=16.0.0"
|
|
10
|
+
},
|
|
7
11
|
"main": "./output/index.js",
|
|
8
12
|
"types": "./output/index.d.ts",
|
|
9
13
|
"exports": {
|
|
10
14
|
".": {
|
|
11
15
|
"types": "./output/index.d.ts",
|
|
12
|
-
"
|
|
13
|
-
"require": "./output/index.js"
|
|
16
|
+
"default": "./output/index.js"
|
|
14
17
|
},
|
|
15
18
|
"./*": {
|
|
16
19
|
"types": "./output/*/index.d.ts",
|
|
17
|
-
"
|
|
18
|
-
"require": "./output/*/index.js"
|
|
20
|
+
"default": "./output/*/index.js"
|
|
19
21
|
}
|
|
20
22
|
},
|
|
21
23
|
"scripts": {
|
|
22
24
|
"test": "vitest run",
|
|
23
|
-
"build": "tsc -p tsconfig.json",
|
|
25
|
+
"build": "node ../../node_modules/typescript/bin/tsc -p tsconfig.json",
|
|
24
26
|
"prepublishOnly": "npm run build",
|
|
25
|
-
"dev": "tsc -p tsconfig.json --watch"
|
|
27
|
+
"dev": "node ../../node_modules/typescript/bin/tsc -p tsconfig.json --watch"
|
|
26
28
|
},
|
|
27
29
|
"files": [
|
|
28
30
|
"output"
|
|
29
31
|
],
|
|
30
32
|
"peerDependencies": {
|
|
31
|
-
"@taicode/common-base": "^3.0
|
|
33
|
+
"@taicode/common-base": "^3.1.0",
|
|
32
34
|
"fastify": "^5.5.0",
|
|
33
|
-
"redis": "^5.
|
|
35
|
+
"redis": "^5.11.0",
|
|
34
36
|
"zod": "^4.1.0"
|
|
35
37
|
},
|
|
36
38
|
"devDependencies": {
|
|
37
|
-
"@types/node": "^22.
|
|
38
|
-
"fastify": "^5.
|
|
39
|
-
"redis": "^5.
|
|
39
|
+
"@types/node": "^22.19.13",
|
|
40
|
+
"fastify": "^5.7.4",
|
|
41
|
+
"redis": "^5.11.0",
|
|
40
42
|
"vitest": "^3.2.4",
|
|
41
|
-
"zod": "^4.
|
|
43
|
+
"zod": "^4.3.6"
|
|
42
44
|
}
|
|
43
45
|
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { RedisQueueCommon } from './redis-queue-common';
|
|
2
|
-
import type { BatchConsumerConfig, QueueStats, RedisQueueRegistry } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Redis 批量队列消费者
|
|
5
|
-
*
|
|
6
|
-
* 批量消费任务,每次处理多条
|
|
7
|
-
*
|
|
8
|
-
* @template K 队列键名类型
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts
|
|
12
|
-
* interface EmailTask {
|
|
13
|
-
* to: string
|
|
14
|
-
* }
|
|
15
|
-
*
|
|
16
|
-
* const consumer = new RedisBatchConsumer<EmailTask>({
|
|
17
|
-
* redisUrl: 'redis://localhost:6379',
|
|
18
|
-
* queueKey: 'email-queue',
|
|
19
|
-
* batchSize: 50,
|
|
20
|
-
* handler: async (dataList) => {
|
|
21
|
-
* await sendEmailsBatch(dataList.map(d => d.to))
|
|
22
|
-
* return catchIt(() => {})
|
|
23
|
-
* }
|
|
24
|
-
* })
|
|
25
|
-
*
|
|
26
|
-
* await consumer.connect() // 自动开始消费
|
|
27
|
-
*
|
|
28
|
-
* // 获取统计信息
|
|
29
|
-
* const stats = await consumer.statistics()
|
|
30
|
-
*
|
|
31
|
-
* // 停止消费
|
|
32
|
-
* consumer.disconnect()
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
export declare class RedisBatchConsumer<K extends keyof RedisQueueRegistry> extends RedisQueueCommon {
|
|
36
|
-
private consumerRunning;
|
|
37
|
-
private consumerInterval;
|
|
38
|
-
private recoveryInterval;
|
|
39
|
-
private processingBatches;
|
|
40
|
-
private readonly config;
|
|
41
|
-
constructor(config: BatchConsumerConfig<K>);
|
|
42
|
-
protected getLogPrefix(): string;
|
|
43
|
-
/**
|
|
44
|
-
* 连接 Redis 并自动启动消费者
|
|
45
|
-
*/
|
|
46
|
-
connect(): Promise<void>;
|
|
47
|
-
/**
|
|
48
|
-
* 断开 Redis 连接并停止消费者
|
|
49
|
-
*/
|
|
50
|
-
disconnect(): void;
|
|
51
|
-
/**
|
|
52
|
-
* 批量处理任务
|
|
53
|
-
*/
|
|
54
|
-
private processBatch;
|
|
55
|
-
/**
|
|
56
|
-
* 启动恢复机制
|
|
57
|
-
*/
|
|
58
|
-
private startRecovery;
|
|
59
|
-
/**
|
|
60
|
-
* 停止恢复机制
|
|
61
|
-
*/
|
|
62
|
-
private stopRecovery;
|
|
63
|
-
/**
|
|
64
|
-
* 启动消费者
|
|
65
|
-
*/
|
|
66
|
-
private startConsumer;
|
|
67
|
-
/**
|
|
68
|
-
* 停止消费者
|
|
69
|
-
*/
|
|
70
|
-
private stopConsumer;
|
|
71
|
-
/**
|
|
72
|
-
* 获取队列统计信息(O(1) 时间复杂度)
|
|
73
|
-
*/
|
|
74
|
-
statistics(): Promise<QueueStats>;
|
|
75
|
-
/**
|
|
76
|
-
* 健康检查
|
|
77
|
-
*/
|
|
78
|
-
health(): Promise<boolean>;
|
|
79
|
-
/**
|
|
80
|
-
* 立即派发批量任务进行处理(仅供测试工具调用)
|
|
81
|
-
*
|
|
82
|
-
* ⚠️ 此方法为 private,仅通过 test-helpers 暴露给测试代码使用
|
|
83
|
-
*
|
|
84
|
-
* @param taskIds 要立即处理的任务 ID 列表
|
|
85
|
-
* @returns Promise,等待所有任务批次处理完成
|
|
86
|
-
*/
|
|
87
|
-
private dispatch;
|
|
88
|
-
}
|
|
89
|
-
//# sourceMappingURL=redis-batch-consumer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|