From 954adde14eced70ab38b8d0d25bc0a4ad27e2f57 Mon Sep 17 00:00:00 2001 From: Pavel Gnedov Date: Fri, 27 May 2022 11:57:07 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=B2=D1=8B=D0=B7=D0=BE=D0=B2=20issue-cache-writer=20?= =?UTF-8?q?=D0=B8=D0=B7=20event-emitter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app.module.ts | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/app.module.ts b/src/app.module.ts index 2d388e4..280e1b3 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -1,12 +1,16 @@ import { EventEmitterModule } from '@app/event-emitter'; import { MainController } from '@app/event-emitter/main/main.controller'; -import { RedmineIssuesCacheWriterModule } from '@app/redmine-issues-cache-writer'; -import { Module } from '@nestjs/common'; +import { + RedmineIssuesCacheWriterModule, + RedmineIssuesCacheWriterService, +} from '@app/redmine-issues-cache-writer'; +import { Logger, Module, OnModuleInit } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import { AppController } from './app.controller'; import { AppService } from './app.service'; import { Issues } from './datasources/issues'; import configuration from './configs/app'; +import { RedmineEventsGateway } from '@app/event-emitter/events/redmine-events.gateway'; @Module({ imports: [ @@ -19,4 +23,23 @@ import configuration from './configs/app'; controllers: [AppController, MainController], providers: [AppService, Issues], }) -export class AppModule {} +export class AppModule implements OnModuleInit { + private logger = new Logger(AppModule.name); + + constructor( + private redmineEventsGateway: RedmineEventsGateway, + private redmineIssuesCacheWriterService: RedmineIssuesCacheWriterService, + ) {} + + onModuleInit() { + const queue = this.redmineEventsGateway.getIssuesChangesQueue(); + const subj = queue.queue; + subj.subscribe(async (issue: any) => { + try { + this.redmineIssuesCacheWriterService.saveIssue(issue); + } catch (ex) { + this.logger.error(`Saving issue error - ${ex}`, null, { issue: issue }); + } + }); + } +}