feat(redis): 添加 redis 及其配置

This commit is contained in:
Ivan Li 2021-03-06 12:23:55 +08:00
parent 8901c49bb3
commit 38d3cb0db8
4 changed files with 34 additions and 2 deletions

View File

@ -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'

View File

@ -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<string>('db.redis.host', 'localhost'),
port: configService.get<number>('db.redis.port', 6379),
password: configService.get<string>('db.redis.password', ''),
keyPrefix: configService.get<string>('db.redis.prefix', 'fennec'),
}),
inject: [ConfigService],
}),
],
controllers: [AppController],
providers: [AppService, AppResolver],

View File

@ -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 {}

View File

@ -17,9 +17,9 @@ export class PipelineTasksService {
private readonly repository: Repository<PipelineTask>,
@InjectRepository(Pipeline)
private readonly pipelineRepository: Repository<Pipeline>,
private readonly redis: RedisService,
@InjectQueue(PIPELINE_TASK_QUEUE)
private readonly queue: Queue<PipelineTask>,
private readonly redis: RedisService,
) {}
async addTask(dto: CreatePipelineTaskInput) {
const pipeline = await this.pipelineRepository.findOneOrFail({