@taicode/common-server 1.0.11 → 1.0.13

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 (51) hide show
  1. package/output/index.d.ts +1 -0
  2. package/output/index.d.ts.map +1 -1
  3. package/output/index.js +1 -0
  4. package/output/redis-queue/index.d.ts +6 -4
  5. package/output/redis-queue/index.d.ts.map +1 -1
  6. package/output/redis-queue/index.js +4 -2
  7. package/output/redis-queue/redis-batch-consumer.d.ts +80 -0
  8. package/output/redis-queue/redis-batch-consumer.d.ts.map +1 -0
  9. package/output/redis-queue/redis-batch-consumer.js +308 -0
  10. package/output/redis-queue/redis-batch-consumer.test.d.ts +7 -0
  11. package/output/redis-queue/redis-batch-consumer.test.d.ts.map +1 -0
  12. package/output/redis-queue/redis-batch-consumer.test.js +265 -0
  13. package/output/redis-queue/redis-queue-common.d.ts +73 -0
  14. package/output/redis-queue/redis-queue-common.d.ts.map +1 -0
  15. package/output/redis-queue/redis-queue-common.js +302 -0
  16. package/output/redis-queue/redis-queue-common.test.d.ts +19 -0
  17. package/output/redis-queue/redis-queue-common.test.d.ts.map +1 -0
  18. package/output/redis-queue/redis-queue-common.test.js +623 -0
  19. package/output/redis-queue/redis-queue-consumer.d.ts +81 -0
  20. package/output/redis-queue/redis-queue-consumer.d.ts.map +1 -0
  21. package/output/redis-queue/redis-queue-consumer.js +297 -0
  22. package/output/redis-queue/redis-queue-consumer.test.d.ts +7 -0
  23. package/output/redis-queue/redis-queue-consumer.test.d.ts.map +1 -0
  24. package/output/redis-queue/redis-queue-consumer.test.js +242 -0
  25. package/output/redis-queue/redis-queue-provider.d.ts +56 -0
  26. package/output/redis-queue/redis-queue-provider.d.ts.map +1 -0
  27. package/output/redis-queue/redis-queue-provider.js +187 -0
  28. package/output/redis-queue/redis-queue-provider.test.d.ts +7 -0
  29. package/output/redis-queue/redis-queue-provider.test.d.ts.map +1 -0
  30. package/output/redis-queue/redis-queue-provider.test.js +114 -0
  31. package/output/redis-queue/types.d.ts +77 -19
  32. package/output/redis-queue/types.d.ts.map +1 -1
  33. package/package.json +1 -1
  34. package/output/logger/logger.d.ts +0 -33
  35. package/output/logger/logger.d.ts.map +0 -1
  36. package/output/logger/logger.js +0 -65
  37. package/output/logger/logger.test.d.ts +0 -2
  38. package/output/logger/logger.test.d.ts.map +0 -1
  39. package/output/logger/logger.test.js +0 -87
  40. package/output/redis-queue/batch-redis-queue.d.ts +0 -136
  41. package/output/redis-queue/batch-redis-queue.d.ts.map +0 -1
  42. package/output/redis-queue/batch-redis-queue.js +0 -573
  43. package/output/redis-queue/batch-redis-queue.test.d.ts +0 -2
  44. package/output/redis-queue/batch-redis-queue.test.d.ts.map +0 -1
  45. package/output/redis-queue/batch-redis-queue.test.js +0 -243
  46. package/output/redis-queue/redis-queue.d.ts +0 -129
  47. package/output/redis-queue/redis-queue.d.ts.map +0 -1
  48. package/output/redis-queue/redis-queue.js +0 -547
  49. package/output/redis-queue/redis-queue.test.d.ts +0 -2
  50. package/output/redis-queue/redis-queue.test.d.ts.map +0 -1
  51. package/output/redis-queue/redis-queue.test.js +0 -234
@@ -1,136 +0,0 @@
1
- import type { BatchTaskQueueConfig, TaskData, Task, QueueStats } from './types';
2
- /**
3
- * 批量任务队列类(泛型)
4
- *
5
- * 提供基于 Redis 的批量任务队列功能,支持:
6
- * - 批量处理任务(每次处理多条)
7
- * - 任务入队和持久化
8
- * - 自动重试机制
9
- * - 任务状态追踪
10
- * - 分布式消费
11
- *
12
- * @template T 任务数据类型
13
- *
14
- * @example
15
- * ```ts
16
- * interface EmailTask {
17
- * to: string
18
- * }
19
- *
20
- * const queue = new BatchRedisQueue<EmailTask>({
21
- * redisUrl: 'redis://localhost:6379',
22
- * queueKey: 'email-batch-queue',
23
- * batchSize: 50,
24
- * handler: async (dataList) => {
25
- * await sendEmailsBatch(dataList.map(d => d.to))
26
- * return catchIt(() => {})
27
- * }
28
- * })
29
- *
30
- * // 连接 Redis(自动启动消费者)
31
- * await queue.connect()
32
- *
33
- * // 入队任务(自动开始处理)
34
- * await queue.enqueue([
35
- * { to: 'user1@example.com' },
36
- * { to: 'user2@example.com' },
37
- * ])
38
- *
39
- * // 获取队列统计信息(O(1) 时间复杂度)
40
- * const stats = await queue.statistics()
41
- * console.log(stats) // { pending: 100, processing: 50, completed: 200, failed: 5 }
42
- * ```
43
- */
44
- export declare class BatchRedisQueue<T extends TaskData = TaskData> {
45
- private consumerRunning;
46
- private redis;
47
- private consumerInterval;
48
- private recoveryInterval;
49
- private processingBatches;
50
- private readonly config;
51
- private readonly handler;
52
- private readonly failedQueue;
53
- private readonly pendingQueue;
54
- private readonly processingQueue;
55
- private readonly completedQueue;
56
- constructor(config: BatchTaskQueueConfig<T>);
57
- /**
58
- * 连接 Redis 并自动启动消费者
59
- */
60
- connect(): Promise<void>;
61
- /**
62
- * 断开 Redis 连接并停止消费者
63
- */
64
- disconnect(): void;
65
- /**
66
- * 将任务推入队列(支持单个或批量)
67
- * @param data 任务数据(单个或数组)。可以在 data 中包含 `id` 字段来实现幂等性
68
- *
69
- * @example
70
- * // 普通任务,自动生成 ID
71
- * await queue.enqueue({ to: 'user@example.com' })
72
- *
73
- * // 幂等任务,手动指定 ID,重复提交会被忽略
74
- * await queue.enqueue({ id: 'email-123', to: 'user@example.com' })
75
- * await queue.enqueue({ id: 'email-123', to: 'user@example.com' }) // 会被跳过
76
- */
77
- enqueue(data: T[]): Promise<string[]>;
78
- enqueue(data: T): Promise<string>;
79
- /**
80
- * 获取任务详情
81
- */
82
- getTask(taskId: string): Promise<Task<T> | null>;
83
- /**
84
- * 更新任务状态并移动到对应队列(原子操作)
85
- */
86
- private applyStatus;
87
- /**
88
- * 批量更新任务状态
89
- */
90
- private applyStatusBatch;
91
- /**
92
- * 根据状态获取对应的队列键
93
- */
94
- private getQueueByStatus;
95
- /**
96
- * 恢复超时的任务
97
- * 检查 processing 队列中的任务,将超时的任务重试或标记为失败
98
- */
99
- private recoverStalledTasks;
100
- /**
101
- * 批量处理任务
102
- */
103
- private processBatch;
104
- /**
105
- * 启动恢复机制(内部方法,自动调用)
106
- */
107
- private startRecovery;
108
- /**
109
- * 停止恢复机制(内部方法,自动调用)
110
- */
111
- private stopRecovery;
112
- /**
113
- * 启动消费者(内部方法,自动调用)
114
- */
115
- private startConsumer;
116
- /**
117
- * 停止消费者(内部方法,自动调用)
118
- */
119
- private stopConsumer;
120
- /**
121
- * 获取队列统计信息
122
- * 返回队列中各种状态任务的详细数量
123
- *
124
- * 使用分离队列设计,O(1) 时间复杂度
125
- */
126
- statistics(): Promise<QueueStats>;
127
- /**
128
- * 清空所有队列
129
- */
130
- clear(): Promise<void>;
131
- /**
132
- * 健康检查
133
- */
134
- health(): Promise<boolean>;
135
- }
136
- //# sourceMappingURL=batch-redis-queue.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"batch-redis-queue.d.ts","sourceRoot":"","sources":["../../source/redis-queue/batch-redis-queue.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAU,QAAQ,EAAE,IAAI,EAAoB,UAAU,EAAE,MAAM,SAAS,CAAA;AAEzG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,qBAAa,eAAe,CAAC,CAAC,SAAS,QAAQ,GAAG,QAAQ;IACxD,OAAO,CAAC,eAAe,CAAQ;IAC/B,OAAO,CAAC,KAAK,CAA+B;IAC5C,OAAO,CAAC,gBAAgB,CAA8B;IACtD,OAAO,CAAC,gBAAgB,CAA8B;IACtD,OAAO,CAAC,iBAAiB,CAAI;IAE7B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoD;IAC3E,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAG7C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAQ;IACpC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAQ;IACrC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAQ;IACxC,OAAO,CAAC,QAA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