Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This snippet should be put into epilog of the messaging enabled process to make sure the final message is properly formulated as a JSON string and global variables to pass messages to a calling process are set. The snippet is valid only for processes that are not parallel enabled and run in single thread mode and should be last code block in epilog tab of the process.

Note:

  • Messages are written into message cube by calling a process with RunProcess to isolate commit event of the message from commit event of the process. This might result in some time differences between the time when message is actually written and process result is indicated and the actual process finish.

  • nProcessReturn code is by definition set to 0 in case of process errors and non-zero otherwise!

Code Block
#Region - Return code & final error message handling
sProcessResultType = If( nErrors = 0, 'success', 'danger' );
If( nErrors > 0 );
    sErrors = NumberToString( nErrors );
    #Region - Failure Message Composition
    sProcessResultMsg = Expand( 'Process has finished with %sErrors% error' | If( nErrors > 1, 's', '') | '.' );
    #EndRegion - Failure Message Composition
    If(  nMultiMsgJSON <= 1 );
        sProcessResultJSON = Expand( '{"process":"%cThisProcName%", "header": "%sProcessResultMsg%", "message":"%sMessage%", "type":"%sProcessResultType%"}' );
    Else;
        sProcessResultJSON = Expand( '{"process":"%cThisProcName%", "header": "%sProcessResultMsg%", "details":{%sMultiMsg%}, "type":"%sProcessResultType%"}' );
    EndIf;
    sMessage = sProcessResultMsg;
    nProcessReturnCode = 0;
    sProcessReturnCode = sProcessResultJSON;
    RunProcess( '}APQ.Cub.ProcessResponseMessage.ImmediateLog',
        'pProcLogParams', sProcLogParams,
        'pProcessStartTime', TimSt(nProcessStartTime, '\Y-\m-\d \h:\i:\s'),
        'pProcessFinishTime', 'now',
        'pUserName', cUserName,
        'pProcessName', cThisProcName,
        'pProcessErrorFile', GetProcessErrorFileName(),
        'pStatus', 'Error',
        'pSuccessMessage', '',
        'pFailureMessage', sProcessResultMsg,
        'pJSONMessage', sProcessReturnCode
    );
    LogOutput( cMsgErrorLevel, Expand( cMsgErrorContent ) );
    ProcessQuit();
Else;
    #Region - Success Message Composition
    sProcessResultMsg = 'Process has finished successfully.';
    #EndRegion - Success Message Composition
    If( nMultiMsgJSON <= 1 );
        sProcessResultJSON = Expand( '{"process":"%cThisProcName%", "header": "%sProcessResultMsg%", "message":"%sMessage%", "type":"%sProcessResultType%"}' );
    Else;
        sProcessResultJSON = Expand( '{"process":"%cThisProcName%", "header": "%sProcessResultMsg%", "message":"%sMessage%", "details":{%sMultiMsg%}, "type":"%sProcessResultType%"}' );
    EndIf;    
    nProcessReturnCode = 1;
    sProcessReturnCode = sProcessResultJSON;
    RunProcess( '}APQ.Cub.ProcessResponseMessage.ImmediateLog',
        'pProcLogParams', sProcLogParams,
        'pProcessStartTime', TimSt(nProcessStartTime, '\Y-\m-\d \h:\i:\s'),
        'pProcessFinishTime', 'now',
        'pUserName', cUserName,
        'pProcessName', cThisProcName,
        'pProcessErrorFile', GetProcessErrorFileName(),
        'pStatus', 'Success',
        'pSuccessMessage', sProcessResultMsg,
        'pFailureMessage', '',
        'pJSONMessage', sProcessReturnCode
    );
    LogOutput('INFO', Expand( 'Process:%cThisProcName%: %sMessage%' ) );   
EndIf;
#EndRegion - Return code & final error message handling

Final Message with Record Count and Time Stats

You should use this snippet when you want to indicate process run time and volume of data it has processes. In order to use this snippet you should replace region Success Message Composition in the epilog in above snippet. You will have to declare variables to store number of records processed (either in Metadata or Data - depends on logic of your process) in Prolog in order to use this snippet and increment the record counter each time a record is successfully processed in respective tab.

Prolog

Code Block
nDataRecordCount = 0;

Data

Code Block
nDataRecordCount = nDataRecordCount + 1;

Epilog

Code Block
    #Region - Success Message Composition
    nTime = NOW();
    nDeltaTime = ROUND( (nTime - nTimeStart) / ( 60 * 60 * 24 ) );
    sDeltaTime = NumberToString( nDeltaTime );
    sRateAVG = NumberToString( nDataRecordCount \ nDeltaTime );
    sDataRecordCount = NumberToString(nDataRecordCount);
    If( nDataRecordCount = 0 );
        sMessage = Expand( 'No records were processed!' );
        sProcessResultMsg = Expand( 'Process has finished without errors.' );
    Else;  
        sMessage = Expand( 'Successfully processed %sDataRecordCount% records in %sDeltaTime% s. Average throughput=%sRateAVG% records/s.' );
        sProcessResultMsg = Expand( 'Process has finished successfully.' );
    EndIf;
    #EndRegion - Success Message Composition