From 38d3cb0db837d5785a888f2e71738a1630bc7a33 Mon Sep 17 00:00:00 2001 From: Ivan Li Date: Sat, 6 Mar 2021 12:23:55 +0800 Subject: [PATCH] =?UTF-8?q?feat(redis):=20=E6=B7=BB=E5=8A=A0=20redis=20?= =?UTF-8?q?=E5=8F=8A=E5=85=B6=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.yml.example | 5 +++++ src/app.module.ts | 11 +++++++++++ src/pipeline-tasks/pipeline-tasks.module.ts | 18 +++++++++++++++++- src/pipeline-tasks/pipeline-tasks.service.ts | 2 +- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/config.yml.example b/config.yml.example index 3aa6f0a..a7e2586 100644 --- a/config.yml.example +++ b/config.yml.example @@ -9,5 +9,10 @@ db: database: fennec username: fennec password: + redis: + host: 192.168.31.194 + port: 6379 + password: + prefix: fennec workspaces: root: '/Users/ivanli/Projects/fennec/workspaces' \ No newline at end of file diff --git a/src/app.module.ts b/src/app.module.ts index b6c5144..030be39 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -10,6 +10,7 @@ import { ReposModule } from './repos/repos.module'; import { PipelinesModule } from './pipelines/pipelines.module'; import { PipelineTasksModule } from './pipeline-tasks/pipeline-tasks.module'; import configuration from './commons/config/configuration'; +import { RedisModule } from 'nestjs-redis'; @Module({ imports: [ @@ -43,6 +44,16 @@ import configuration from './commons/config/configuration'; ReposModule, PipelinesModule, PipelineTasksModule, + RedisModule.forRootAsync({ + imports: [ConfigModule], + useFactory: (configService: ConfigService) => ({ + host: configService.get('db.redis.host', 'localhost'), + port: configService.get('db.redis.port', 6379), + password: configService.get('db.redis.password', ''), + keyPrefix: configService.get('db.redis.prefix', 'fennec'), + }), + inject: [ConfigService], + }), ], controllers: [AppController], providers: [AppService, AppResolver], diff --git a/src/pipeline-tasks/pipeline-tasks.module.ts b/src/pipeline-tasks/pipeline-tasks.module.ts index 447f9d1..4f99cd9 100644 --- a/src/pipeline-tasks/pipeline-tasks.module.ts +++ b/src/pipeline-tasks/pipeline-tasks.module.ts @@ -5,9 +5,25 @@ import { TypeOrmModule } from '@nestjs/typeorm'; import { PipelineTask } from './pipeline-task.entity'; import { Pipeline } from '../pipelines/pipeline.entity'; import { ReposModule } from '../repos/repos.module'; +import { RedisModule } from 'nestjs-redis'; +import { BullModule } from '@nestjs/bull'; +import { + PIPELINE_TASK_QUEUE, + PIPELINE_TASK_LOG_QUEUE, +} from './pipeline-tasks.constants'; @Module({ - imports: [TypeOrmModule.forFeature([PipelineTask, Pipeline]), ReposModule], + imports: [ + TypeOrmModule.forFeature([PipelineTask, Pipeline]), + BullModule.registerQueue( + { + name: PIPELINE_TASK_QUEUE, + }, + { name: PIPELINE_TASK_LOG_QUEUE }, + ), + RedisModule, + ReposModule, + ], providers: [PipelineTasksService, PipelineTasksResolver], }) export class PipelineTasksModule {} diff --git a/src/pipeline-tasks/pipeline-tasks.service.ts b/src/pipeline-tasks/pipeline-tasks.service.ts index 5e94020..75660d8 100644 --- a/src/pipeline-tasks/pipeline-tasks.service.ts +++ b/src/pipeline-tasks/pipeline-tasks.service.ts @@ -17,9 +17,9 @@ export class PipelineTasksService { private readonly repository: Repository, @InjectRepository(Pipeline) private readonly pipelineRepository: Repository, - private readonly redis: RedisService, @InjectQueue(PIPELINE_TASK_QUEUE) private readonly queue: Queue, + private readonly redis: RedisService, ) {} async addTask(dto: CreatePipelineTaskInput) { const pipeline = await this.pipelineRepository.findOneOrFail({