返回 AiToEarn
README.md
1 # @yikart/aitoearn-queue
2
3 统一的队列管理模块,基于 BullMQ 实现。
4
5 ## 功能
6
7 - 统一的队列服务(QueueService)
8 - 集中的队列名称管理(QueueName 枚举)
9 - 内置 Redis 连接管理
10 - 类型安全的任务数据定义
11
12 ## 使用方法
13
14 ### 在应用中导入模块
15
16 ```typescript
17 import { AitoearnQueueModule } from '../src/queue.module'
18
19 @Module({
20 imports: [
21 AitoearnQueueModule.forRoot({
22 redis: {
23 host: 'localhost',
24 port: 6379,
25 },
26 prefix: '{bull}',
27 }),
28 ],
29 })
30 export class AppModule {}
31 ```
32
33 ### 使用队列服务
34
35 ```typescript
36 import { QueueService } from '../src/queue.module'
37
38 @Injectable()
39 export class MyService {
40 constructor(private readonly queueService: QueueService) {}
41
42 async addJob() {
43 await this.queueService.addMaterialGenerateJobs([
44 { taskId: '123' }
45 ])
46 }
47 }
48 ```
49
50 ## 注意事项
51
52 - 不要直接使用 `@InjectQueue` 装饰器,请使用 `QueueService`
53 - 不要直接导入 `bullmq` 的类型,队列模块已提供所需接口
54 - Consumer(队列消费者)仍然保留在各应用中
55
55 lines MARKDOWN