Инициализация модуля event-emitter на старте
This commit is contained in:
parent
e7bb2ba8cd
commit
4e31ebaafd
1 changed files with 40 additions and 2 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { DynamicModule, Module } from '@nestjs/common';
|
||||
import { DynamicModule, Logger, Module, OnModuleInit } from '@nestjs/common';
|
||||
import { EventEmitterService } from './event-emitter.service';
|
||||
import { RedmineEventsGateway } from './events/redmine-events.gateway';
|
||||
import { ServeStaticModule } from '@nestjs/serve-static';
|
||||
|
|
@ -12,9 +12,10 @@ import { RedmineIssuesCacheWriterService } from './issue-cache-writer/redmine-is
|
|||
import { CouchDb } from './couchdb-datasources/couchdb';
|
||||
import { Users } from './couchdb-datasources/users';
|
||||
import { Issues } from './couchdb-datasources/issues';
|
||||
import { RedmineTypes } from '@app/redmine-types/index';
|
||||
|
||||
@Module({})
|
||||
export class EventEmitterModule {
|
||||
export class EventEmitterModule implements OnModuleInit {
|
||||
static register(params?: ModuleParams): DynamicModule {
|
||||
return {
|
||||
module: EventEmitterModule,
|
||||
|
|
@ -45,4 +46,41 @@ export class EventEmitterModule {
|
|||
controllers: [MainController],
|
||||
};
|
||||
}
|
||||
|
||||
private logger = new Logger(EventEmitterModule.name);
|
||||
|
||||
constructor(
|
||||
private redmineEventsGateway: RedmineEventsGateway,
|
||||
private redmineIssuesCacheWriterService: RedmineIssuesCacheWriterService,
|
||||
) {}
|
||||
|
||||
onModuleInit() {
|
||||
const queue = this.redmineEventsGateway.getIssuesChangesQueue();
|
||||
const subj = queue.queue;
|
||||
subj.subscribe(async (issues: any) => {
|
||||
this.logger.debug(`Changed issues = ${JSON.stringify(issues)}`);
|
||||
|
||||
for (let i = 0; i < issues.length; i++) {
|
||||
const issue: RedmineTypes.Issue = issues[i];
|
||||
|
||||
try {
|
||||
this.logger.debug(
|
||||
`Save issue #${issue.id} - ${JSON.stringify(issue)}`,
|
||||
);
|
||||
|
||||
const response = await this.redmineIssuesCacheWriterService.saveIssue(
|
||||
issue,
|
||||
);
|
||||
|
||||
this.logger.debug(
|
||||
`Save issue #${issue.id} response = ${JSON.stringify(response)}`,
|
||||
);
|
||||
} catch (ex) {
|
||||
this.logger.error(`Saving issue error - ${ex}`, null, {
|
||||
issue: issue,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue