feat(repos): 添加消息队列分发。BAK

This commit is contained in:
Ivan 2021-02-25 16:11:06 +08:00
parent 5b2a017858
commit 7ea8505873
7 changed files with 44 additions and 2 deletions

View File

@ -1,7 +1,6 @@
env: dev env: dev
http: http:
port: 7122 port: 7122
db: db:
postgres: postgres:
host: 192.168.31.194 host: 192.168.31.194
@ -9,5 +8,9 @@ db:
database: fennec database: fennec
username: fennec username: fennec
password: password:
redis:
mq:
host: localhost
port: 6379
workspaces: workspaces:
root: '/Users/ivanli/Projects/fennec/workspaces' root: '/Users/ivanli/Projects/fennec/workspaces'

View File

@ -8,6 +8,7 @@ import { AppService } from './app.service';
import { ProjectsModule } from './projects/projects.module'; import { ProjectsModule } from './projects/projects.module';
import { ReposModule } from './repos/repos.module'; import { ReposModule } from './repos/repos.module';
import configuration from './commons/config/configuration'; import configuration from './commons/config/configuration';
import { BullModule } from '@nestjs/bull';
@Module({ @Module({
imports: [ imports: [
@ -37,6 +38,16 @@ import configuration from './commons/config/configuration';
}), }),
inject: [ConfigService], inject: [ConfigService],
}), }),
BullModule.forRootAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
redis: {
host: configService.get<string>('redis.mq.host', 'localhost'),
port: configService.get<number>('redis.mq.port', 6379),
},
}),
inject: [ConfigService],
}),
ProjectsModule, ProjectsModule,
ReposModule, ReposModule,
], ],

View File

@ -0,0 +1 @@
export const WORKSPACE_ACTION = 'workspace-action';

View File

@ -4,9 +4,17 @@ import { Project } from '../projects/project.entity';
import { ReposResolver } from './repos.resolver'; import { ReposResolver } from './repos.resolver';
import { ReposService } from './repos.service'; import { ReposService } from './repos.service';
import { ConfigModule } from '@nestjs/config'; import { ConfigModule } from '@nestjs/config';
import { BullModule } from '@nestjs/bull';
import { WORKSPACE_ACTION } from './repos.constants';
@Module({ @Module({
imports: [TypeOrmModule.forFeature([Project]), ConfigModule], imports: [
TypeOrmModule.forFeature([Project]),
ConfigModule,
BullModule.registerQueue({
name: WORKSPACE_ACTION,
}),
],
providers: [ReposResolver, ReposService], providers: [ReposResolver, ReposService],
}) })
export class ReposModule {} export class ReposModule {}

View File

@ -0,0 +1,8 @@
import { Process, Processor } from '@nestjs/bull';
import { WORKSPACE_ACTION } from './repos.constants';
@Processor(WORKSPACE_ACTION)
export class WorkspaceActionConsumer {
@Process()
async dispatch() {}
}

View File

@ -0,0 +1,5 @@
import { WorkspaceActions } from './workspace-actions.enum';
export class WorkspaceAction {
action: WorkspaceActions;
}

View File

@ -0,0 +1,6 @@
export enum WorkspaceActions {
checkoutBranch = 'checkoutBranch',
checkoutCommit = 'checkoutCommit',
listLogs = 'listLogs',
listBranches = 'listBranches',
}