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

77 lines
2.2 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-05 19:11:39 +08:00
import { EXCHANGE_PIPELINE_TASK_FANOUT } from './pipeline-tasks.constants';
import { PipelineTaskLogger } from './pipeline-task.logger';
@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,
},
},
{
name: 'stop-pipeline-task',
type: 'fanout',
options: {
durable: true,
2021-06-05 19:11:39 +08:00
autoDelete: true,
},
},
{
name: 'update-pipeline-task',
type: 'fanout',
options: {
durable: false,
2021-06-05 19:11:39 +08:00
autoDelete: true,
},
},
{
name: EXCHANGE_PIPELINE_TASK_FANOUT,
type: 'fanout',
options: {
durable: false,
autoDelete: true,
},
},
],
}),
inject: [ConfigService],
}),
2021-03-06 12:23:55 +08:00
],
providers: [
PipelineTasksService,
PipelineTasksResolver,
PipelineTaskRunner,
PipelineTaskLogger,
{
provide: 'spawn',
useValue: spawn,
},
],
exports: [PipelineTasksService],
})
export class PipelineTasksModule {}