1+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
12/* eslint-disable @typescript-eslint/no-explicit-any */
23import apm from 'elastic-apm-node' ;
34import { ChannelResult } from '../classes/channel-result' ;
@@ -9,15 +10,25 @@ import { CMSRequest } from '../classes/cms-request';
910import { Alert } from '../classes/alert' ;
1011import { TADPResult } from '../classes/tadp-result' ;
1112
13+ const calculateDuration = ( startHrTime : Array < number > , endHrTime : Array < number > ) : number => {
14+ return ( endHrTime [ 0 ] - startHrTime [ 0 ] ) * 1000 + ( endHrTime [ 1 ] - startHrTime [ 1 ] ) / 1000000 ;
15+ } ;
16+
1217export const handleExecute = async ( rawTransaction : any ) : Promise < any > => {
1318 try {
19+ const startHrTime = process . hrtime ( ) ;
1420 // Get the request body and parse it to variables
1521 const transaction = rawTransaction . transaction ;
1622 const networkMap = rawTransaction . networkMap as NetworkMap ;
1723 const channelResult = rawTransaction . channelResult as ChannelResult ;
1824
1925 // Send every channel request to the service function
20- const toReturn : TADPResult = { id : '' , cfg : '' , channelResult : [ ] } ;
26+ const toReturn : TADPResult = {
27+ id : '' ,
28+ cfg : '' ,
29+ channelResult : [ ] ,
30+ prcgTm : 0 ,
31+ } ;
2132
2233 const message = networkMap . messages . find ( ( tran ) => tran . txTp === transaction . TxTp ) ;
2334
@@ -29,10 +40,12 @@ export const handleExecute = async (rawTransaction: any): Promise<any> => {
2940
3041 if ( channelResults . some ( ( c ) => c . status === 'Review' ) ) review = true ;
3142 toReturn . channelResult = channelResults ;
32-
43+ toReturn . prcgTm = calculateDuration ( startHrTime , process . hrtime ( ) ) ;
3344 const alert = new Alert ( ) ;
3445 alert . tadpResult = toReturn ;
3546 alert . status = review === true ? 'ALRT' : 'NALT' ;
47+ alert . prcgTmCRSP = rawTransaction . prcgTmCRSP ;
48+ alert . prcgTmDP = rawTransaction . prcgTmDP ;
3649
3750 const result : CMSRequest = {
3851 message : `Successfully completed ${ channelResults . length } channels` ,
@@ -62,6 +75,7 @@ export const handleChannels = async (
6275 channelResult : ChannelResult ,
6376) : Promise < ChannelResult [ ] > => {
6477 const span = apm . startSpan ( 'handleChannels' ) ;
78+
6579 try {
6680 const transactionType = Object . keys ( transaction ) . find ( ( k ) => k !== 'TxTp' ) ?? '' ;
6781 const transactionID = transaction [ transactionType ] . GrpHdr . MsgId ;
0 commit comments