fennec-be/src/pipeline-tasks/pipeline-tasks.module.ts

73 lines
2.1 KiB
TypeScript
Raw Normal View History

import { Module } from '@nestjs/common';
import { PipelineTasksService } from './pipeline-tasks.service';
import { PipelineTasksResolver } from './pipeline-tasks.resolver';
import { TypeOrmModule } from '@nestjs/typeorm';
import { PipelineTask } from './pipeline-task.entity';
import { Pipeline } from '../pipelines/pipeline.entity';
import { ReposModule } from '../repos/repos.module';
2021-03-06 12:23:55 +08:00
import { RedisModule } from 'nestjs-redis';
import { RabbitMQModule } from '@golevelup/nestjs-rabbitmq';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { PipelineTaskRunner } from './pipeline-task.runner';
import { spawn } from 'child_process';
2021-06-06 22:11:30 +08:00
import {
EXCHANGE_PIPELINE_TASK_FANOUT,
EXCHANGE_PIPELINE_TASK_TOPIC,
} from './pipeline-tasks.constants';
import { PipelineTaskLogger } from './pipeline-task.logger';
2021-06-06 22:11:30 +08:00
import { PipelineTaskFlushService } from './pipeline-task-flush.service';
@Module({
2021-03-06 12:23:55 +08:00
imports: [
TypeOrmModule.forFeature([PipelineTask, Pipeline]),
RedisModule,
ReposModule,
RabbitMQModule.forRootAsync(RabbitMQModule, {
imports: [ConfigModule],
useFactory: (configService: ConfigService) => ({
uri: configService.get<string>('db.rabbitmq.uri'),
exchanges: [
{
name: 'new-pipeline-task',
type: 'fanout',
options: {
durable: true,
2021-06-05 19:11:39 +08:00
autoDelete: true,
},
},
2021-06-05 19:11:39 +08:00
{
name: EXCHANGE_PIPELINE_TASK_FANOUT,
type: 'fanout',
options: {
durable: false,
autoDelete: true,
},
},
2021-06-06 22:11:30 +08:00
{
name: EXCHANGE_PIPELINE_TASK_TOPIC,
type: 'topic',
options: {
durable: false,
autoDelete: true,
},
},
],
}),
inject: [ConfigService],
}),
2021-03-06 12:23:55 +08:00
],
providers: [
PipelineTasksService,
PipelineTasksResolver,
PipelineTaskRunner,
PipelineTaskLogger,
{
provide: 'spawn',
useValue: spawn,
},
2021-06-06 22:11:30 +08:00
PipelineTaskFlushService,
],
exports: [PipelineTasksService],
})
export class PipelineTasksModule {}