log: add APM to handler
parent
583b754315
commit
fcaf4a07a1
|
@ -23,6 +23,10 @@ export class CouchService {
|
||||||
for (const database of DatabaseListen) {
|
for (const database of DatabaseListen) {
|
||||||
const db = nano.db.use(database);
|
const db = nano.db.use(database);
|
||||||
db.changesReader.start({ includeDocs: true }).on('change', (change) => {
|
db.changesReader.start({ includeDocs: true }).on('change', (change) => {
|
||||||
|
Logger.log(
|
||||||
|
`Receive Data from ${database}: ${change?.id}`,
|
||||||
|
'CouchService',
|
||||||
|
);
|
||||||
this.changeDoc(change, database);
|
this.changeDoc(change, database);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ export class SeasonPeriodHolidayHandler
|
||||||
const queryRunner = this.dataService
|
const queryRunner = this.dataService
|
||||||
.getRepository()
|
.getRepository()
|
||||||
.manager.connection.createQueryRunner();
|
.manager.connection.createQueryRunner();
|
||||||
const holidayDates = [];
|
|
||||||
|
|
||||||
if (event.data.data.holidays?.length) {
|
if (event.data.data.holidays?.length) {
|
||||||
// foreach holiday
|
// foreach holiday
|
||||||
|
@ -35,9 +34,11 @@ export class SeasonPeriodHolidayHandler
|
||||||
});
|
});
|
||||||
holidayDate.priority = 1;
|
holidayDate.priority = 1;
|
||||||
|
|
||||||
await this.dataService.createBatch(queryRunner, SeasonPeriodModel, [
|
await this.dataService.create(
|
||||||
|
queryRunner,
|
||||||
|
SeasonPeriodModel,
|
||||||
holidayDate,
|
holidayDate,
|
||||||
]);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete data
|
// delete data
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { TransactionModel } from '../../../data/models/transaction.model';
|
||||||
import { mappingRevertTransaction } from '../managers/helpers/mapping-transaction.helper';
|
import { mappingRevertTransaction } from '../managers/helpers/mapping-transaction.helper';
|
||||||
import { apm } from '../../../../../../core/apm';
|
import { apm } from '../../../../../../core/apm';
|
||||||
|
|
||||||
// @EventsHandler(ChangeDocEvent)
|
@EventsHandler(ChangeDocEvent)
|
||||||
export class PosTransactionHandler implements IEventHandler<ChangeDocEvent> {
|
export class PosTransactionHandler implements IEventHandler<ChangeDocEvent> {
|
||||||
constructor(
|
constructor(
|
||||||
private dataService: TransactionDataService,
|
private dataService: TransactionDataService,
|
||||||
|
@ -19,6 +19,10 @@ export class PosTransactionHandler implements IEventHandler<ChangeDocEvent> {
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async handle(event: ChangeDocEvent) {
|
async handle(event: ChangeDocEvent) {
|
||||||
|
const apmTransactions = apm.startTransaction(
|
||||||
|
`ChangeDocEvent ${event?.data?.database}`,
|
||||||
|
'handler',
|
||||||
|
);
|
||||||
try {
|
try {
|
||||||
const database = event.data.database;
|
const database = event.data.database;
|
||||||
const data = event.data.data;
|
const data = event.data.data;
|
||||||
|
@ -75,11 +79,17 @@ export class PosTransactionHandler implements IEventHandler<ChangeDocEvent> {
|
||||||
sales_price_formula: sales_formula.formula_string,
|
sales_price_formula: sales_formula.formula_string,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
apmTransactions.setLabel('Code', data?.code);
|
||||||
|
|
||||||
await this.dataService.create(queryRunner, TransactionModel, data);
|
await this.dataService.create(queryRunner, TransactionModel, data);
|
||||||
|
apmTransactions.result = 'Success';
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
apmTransactions.result = 'Failed';
|
||||||
apm.captureError(error);
|
apm.captureError(error);
|
||||||
console.log('error handling pos transaction couch');
|
console.log('error handling pos transaction couch');
|
||||||
|
} finally {
|
||||||
|
apmTransactions.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue