diff --git a/config.yml.example b/config.yml.example index 3aa6f0a..dd2fed2 100644 --- a/config.yml.example +++ b/config.yml.example @@ -1,7 +1,6 @@ env: dev http: port: 7122 - db: postgres: host: 192.168.31.194 @@ -9,5 +8,9 @@ db: database: fennec username: fennec password: +redis: + mq: + host: localhost + port: 6379 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 1f307c8..975338f 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -8,6 +8,7 @@ import { AppService } from './app.service'; import { ProjectsModule } from './projects/projects.module'; import { ReposModule } from './repos/repos.module'; import configuration from './commons/config/configuration'; +import { BullModule } from '@nestjs/bull'; @Module({ imports: [ @@ -37,6 +38,16 @@ import configuration from './commons/config/configuration'; }), inject: [ConfigService], }), + BullModule.forRootAsync({ + imports: [ConfigModule], + useFactory: async (configService: ConfigService) => ({ + redis: { + host: configService.get('redis.mq.host', 'localhost'), + port: configService.get('redis.mq.port', 6379), + }, + }), + inject: [ConfigService], + }), ProjectsModule, ReposModule, ], diff --git a/src/repos/repos.constants.ts b/src/repos/repos.constants.ts new file mode 100644 index 0000000..87adf34 --- /dev/null +++ b/src/repos/repos.constants.ts @@ -0,0 +1 @@ +export const WORKSPACE_ACTION = 'workspace-action'; diff --git a/src/repos/repos.module.ts b/src/repos/repos.module.ts index ae00feb..65c6c2f 100644 --- a/src/repos/repos.module.ts +++ b/src/repos/repos.module.ts @@ -4,9 +4,17 @@ import { Project } from '../projects/project.entity'; import { ReposResolver } from './repos.resolver'; import { ReposService } from './repos.service'; import { ConfigModule } from '@nestjs/config'; +import { BullModule } from '@nestjs/bull'; +import { WORKSPACE_ACTION } from './repos.constants'; @Module({ - imports: [TypeOrmModule.forFeature([Project]), ConfigModule], + imports: [ + TypeOrmModule.forFeature([Project]), + ConfigModule, + BullModule.registerQueue({ + name: WORKSPACE_ACTION, + }), + ], providers: [ReposResolver, ReposService], }) export class ReposModule {} diff --git a/src/repos/workspace-action.consumer.ts b/src/repos/workspace-action.consumer.ts new file mode 100644 index 0000000..1bdf03f --- /dev/null +++ b/src/repos/workspace-action.consumer.ts @@ -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() {} +} diff --git a/src/repos/workspace-action.model.ts b/src/repos/workspace-action.model.ts new file mode 100644 index 0000000..e5ca154 --- /dev/null +++ b/src/repos/workspace-action.model.ts @@ -0,0 +1,5 @@ +import { WorkspaceActions } from './workspace-actions.enum'; + +export class WorkspaceAction { + action: WorkspaceActions; +} diff --git a/src/repos/workspace-actions.enum.ts b/src/repos/workspace-actions.enum.ts new file mode 100644 index 0000000..25953ef --- /dev/null +++ b/src/repos/workspace-actions.enum.ts @@ -0,0 +1,6 @@ +export enum WorkspaceActions { + checkoutBranch = 'checkoutBranch', + checkoutCommit = 'checkoutCommit', + listLogs = 'listLogs', + listBranches = 'listBranches', +}