Исправлена передача issue и дополнительное логирование
This commit is contained in:
parent
954adde14e
commit
8bef7ecca4
2 changed files with 30 additions and 9 deletions
|
|
@ -14,9 +14,11 @@ export class RedmineIssuesCacheWriterService {
|
|||
>,
|
||||
) {}
|
||||
|
||||
async saveIssue(issue: any): Promise<SaveResponse> {
|
||||
async saveIssue(issue: RedmineTypes.Issue): Promise<SaveResponse> {
|
||||
this.logger.debug(
|
||||
`Saving issue ${issue?.id || '-'} - ${issue?.subject || '-'}`,
|
||||
`Saving issue ${issue?.id || '-'} - ${
|
||||
issue?.subject || '-'
|
||||
}, issue data = ${JSON.stringify(issue)}`,
|
||||
);
|
||||
const id = Number(issue['id']);
|
||||
let prevIssue: (nano.DocumentGetResponse & RedmineTypes.Issue) | null;
|
||||
|
|
@ -28,11 +30,11 @@ export class RedmineIssuesCacheWriterService {
|
|||
}
|
||||
let newIssue: nano.DocumentGetResponse & RedmineTypes.Issue;
|
||||
if (!prevIssue) {
|
||||
newIssue = { ...issue };
|
||||
newIssue = { ...(issue as any) };
|
||||
newIssue._id = String(id);
|
||||
await issueDb.insert(newIssue);
|
||||
} else {
|
||||
const newIssue = { ...issue };
|
||||
newIssue = { ...(issue as any) };
|
||||
newIssue._id = String(id);
|
||||
newIssue._rev = prevIssue._rev;
|
||||
await issueDb.insert(newIssue);
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ 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';
|
||||
import { RedmineTypes } from '@app/redmine-types/index';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
|
@ -34,11 +35,29 @@ export class AppModule implements OnModuleInit {
|
|||
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 });
|
||||
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