project QadFinancials > class TConCheck > method DaemonQueues

Description

Consistency check of daemon queues.


Parameters


icFileinputcharacter
ocConCheckLineDetResultoutputcharacter
otConCheckLineDetStartDateoutputdate
oiConCheckLineDetStartTimeoutputinteger
oiConCheckLineDetDurationoutputinteger
iiCompanyIDinputinteger
iiPeriodIDinputinteger
iiSessionIDinputinteger
oiErrorNumbersoutputinteger
ocConCheckLineDetVersionoutputcharacter
icAppVersioninputcharacter
icSumFileinputcharacterSummary file
ihTranslationHandleinputhandle
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method TConCheck.MainEntry


program code (program1/tconcheck.p)

/* ============================================================================================ */
/* This is the method for checking Daemon Queues                                                */
/* ============================================================================================ */
/* Validations:                                                                                 */
/* ERROR1		There are still unprocessed records in the history daemon queue                 */
/* ERROR2		There are still unprocessed records in the cross-company daemon queue     		*/
/* ERROR3		There are still unprocessed records in the balance daemon queue                 */
/* ERROR4		There are still unprocessed records in the cube daemon queue                    */
/* ============================================================================================ */
assign oiReturnStatus             = -98
	   vdStartEtime               = etime(no)
       otConCheckLineDetStartDate = now
       oiConCheckLineDetStartTime = time
       oiErrorNumbers             = 0
       ocConCheckLineDetVersion   = icAppVersion + '.1'
       viBalanceErrorCnt          = 0
       viBalanceQueueCnt          = 0
       viCrossCyErrorCnt          = 0
       viCrossCyQueueCnt          = 0
       viCubeErrorCnt             = 0
       viCubeQueueCnt             = 0
       viHistErrorCnt             = 0
       viHistQueueCnt             = 0.

/* open logfile stream */
OUTPUT STREAM sTechOut TO value(icFile) APPEND. 

put stream sTechOut unformatted ' 'skip.
put stream sTechOut unformatted '##### Daemon Queues #####' skip.
PUT STREAM sTechOut unformatted 'Version: ' ocConCheckLineDetVersion skip.
put stream sTechOut unformatted 'Validation Start At: '  string(now, '99/99/9999 HH:MM:SS') skip.

MAIN_BLOCK: 
do:
    /* init values */
    assign ocConCheckLineDetResult = {&CONCHECKRESULT-PASSED}.
    
    /* ====================================================== */
    /* Step1 - checking input parameters and initializing     */
    /* ====================================================== */
    if iiCompanyID = ? or iiCompanyID = 0 
    then do:
       assign ocConCheckLineDetResult = {&CONCHECKRESULT-FAILED}.
       PUT STREAM sTechOut unformatted "**Error** Input parameter CompanyID is null." skip. 
       LEAVE MAIN_BLOCK.
    end.

    find Company where
         Company.Company_ID = iiCompanyID
         no-lock no-error.
    if not available Company
    then do :
       assign ocConCheckLineDetResult = {&CONCHECKRESULT-FAILED}.
       PUT STREAM sTechOut unformatted "**Error** Company is not found with iiCompanyID= " iiCompanyID "." skip. 
       LEAVE MAIN_BLOCK.
    end.

    if iiPeriodID = ? or 
       iiPeriodID = 0 
    then do:
       assign ocConCheckLineDetResult = {&CONCHECKRESULT-FAILED}.
       PUT STREAM sTechOut unformatted "**Error** Input parameter PeriodID is null." skip. 
       LEAVE MAIN_BLOCK.
    end.

	/* Get YearPeriod by iiPeriodID */
    find first Period of Company where 
               Period_id = iiPeriodID 
               no-lock no-error.    

    if not available Period
    then do:
       assign ocConCheckLineDetResult = {&CONCHECKRESULT-FAILED}.
       PUT STREAM sTechOut unformatted "**Error** Period not found with iiPeriodID= " iiPeriodID "." skip. 
       LEAVE MAIN_BLOCK.
    end.
	/* Check if History Daemon Queue is empty */
    for each QPostingLine where QPostingLine.Company_ID = iiCompanyID 
                                        and QPostingLine.QPostingDate <= Period.PeriodEndDate no-lock:
        assign vlIsQueue = yes.
        for each fcDaemon no-lock where DaemonName = {&HISTORYDAEMON},
            first fcDaemonQueue of fcDaemon where DaemonQueueStatus = {&DAEMONQUEUESTATUS-PROCESSEDERR} 
                                                 and DaemonqueueRef = string(QPostingLine_ID) no-lock:
            assign viHistErrorCnt = viHistErrorCnt + 1
                   vlIsQueue = no.
            leave.
        end.
        if vlIsQueue 
        then do:
            assign viHistQueueCnt = viHistQueueCnt + 1.
        end.
        if viHistQueueCnt > 0 and viHistErrorCnt > 0 then leave.
    end. /* end for each QPostingLine */
	/* Check if CrossCy Daemon Queue is empty */
    for each QCrossCyPosting where QCrossCyPosting.Company_ID = iiCompanyID 
                                    and QCrossCyPostingCreateDate <= Period.PeriodEndDate no-lock:

        assign vlIsQueue = yes.
        for each fcDaemon no-lock where DaemonName = {&CROSSCOMPANYDAEMON},
            first fcDaemonQueue of fcDaemon where DaemonQueueStatus = {&DAEMONQUEUESTATUS-PROCESSEDERR} 
                                                 and DaemonqueueRef = string(QCrossCyPosting_ID) no-lock:
            assign viCrossCyErrorCnt = viCrossCyErrorCnt + 1
                   vlIsQueue = no.
            leave.
        end.
        if vlIsQueue then
            assign viCrossCyQueueCnt = viCrossCyQueueCnt + 1.
        if viCrossCyErrorCnt > 0 and viCrossCyQueueCnt > 0 then leave.
    end. /* end for each QCrossCyPosting */

    /* Check if Balance Daemon Queue is empty */
    for each QCInvoiceMovement where QCInvoiceMovement.Company_ID = iiCompanyID 
                                    and QCInvoiceMovement.MovementYearPeriod <= Period.PeriodYearPeriod no-lock:
        assign vlIsQueue = yes.
        for first fcDaemon no-lock where DaemonName = {&BALANCEDAEMON},
            first fcDaemonQueue of fcDaemon where DaemonQueueStatus = {&DAEMONQUEUESTATUS-PROCESSEDERR} 
                                            and DaemonqueueRef = string(QCInvoiceMovement_ID) no-lock:
            assign viBalanceErrorCnt = viBalanceErrorCnt + 1
                   vlIsQueue = no.
            leave.
        end.
        if vlIsQueue then
            assign viBalanceQueueCnt = viBalanceQueueCnt + 1.
        if viBalanceQueueCnt > 0 and viBalanceErrorCnt > 0 then leave.
    end. /* end for each QCInvoiceMovement*/
    if viBalanceQueueCnt = 0 and viBalanceErrorCnt = 0
    then do:
        for each QDInvoiceMovement where QDInvoiceMovement.Company_ID = iiCompanyID 
                                        and QDInvoiceMovement.MovementYearPeriod <= Period.PeriodYearPeriod no-lock:
            assign vlIsQueue = yes.
            for first fcDaemon no-lock where DaemonName = {&BALANCEDAEMON},
                first fcDaemonQueue of fcDaemon where DaemonQueueStatus = {&DAEMONQUEUESTATUS-PROCESSEDERR} 
                                                and DaemonqueueRef = string(QDInvoiceMovement_ID) no-lock:
                assign viBalanceErrorCnt = viBalanceErrorCnt + 1
                       vlIsQueue = no.
                leave.
            end.
            if vlIsQueue then
                assign viBalanceQueueCnt = viBalanceQueueCnt + 1.
            if viBalanceQueueCnt > 0 and viBalanceErrorCnt > 0 then leave.
        end.
    end. /* end if viBalanceQueueCnt */
    /* Check if Cube Daemon Queue is empty */
    for each QFRWCube where QFRWCube.Company_ID = iiCompanyID 
                                    and QFRWCube.QFRWCubePostingDate <= Period.PeriodEndDate no-lock:
        assign vlIsQueue = yes.
        for first fcDaemon no-lock where DaemonName = {&CUBEDAEMON},
            first fcDaemonQueue of fcDaemon where DaemonQueueStatus = {&DAEMONQUEUESTATUS-PROCESSEDERR} 
                                            and DaemonqueueRef = string(QFRWCube_ID) no-lock:
            assign viCubeErrorCnt = viCubeErrorCnt + 1
                   vlIsQueue = no.
            leave.
        end.
        if vlIsQueue then
            assign viCubeQueueCnt = viCubeQueueCnt + 1.
        if viCubeQueueCnt > 0 and viCubeErrorCnt > 0 then leave.
    end. /* end for each QFRWCube */

	if viHistQueueCnt > 0
    then do:
        assign oiErrorNumbers = oiErrorNumbers + 1.
        put stream sTechOut unformatted 'There are unprocessed records in the history daemon queue with a posting date before the selected period end.' skip.       
    end.

    if viHistErrorCnt > 0
    then do:
        assign oiErrorNumbers = oiErrorNumbers + 1.
        put stream sTechOut unformatted 'There are failed queue records in the history daemon with a posting date before the selected period end.' skip.           
    end.
		
    if viCrossCyQueueCnt > 0
    then do:
        assign oiErrorNumbers = oiErrorNumbers + 1.
        put stream sTechOut unformatted 'There are unprocessed records in the cross-company daemon queue with a posting date before the selected period end.' skip.       
    end.
	if viCrossCyErrorCnt > 0
    then do:
        assign oiErrorNumbers = oiErrorNumbers + 1.
        put stream sTechOut unformatted 'There are failed queue records in the cross-company daemon with a posting date before the selected period end.' skip.          
    end.

    if viBalanceQueueCnt > 0
    then do:
        assign oiErrorNumbers = oiErrorNumbers + 1.
        put stream sTechOut unformatted 'There are unprocessed records in the balance daemon queue with a posting date before the selected period end.' skip.       
    end.
    if viBalanceErrorCnt > 0
    then do:
        assign oiErrorNumbers = oiErrorNumbers + 1.
        put stream sTechOut unformatted 'There are failed queue records in the balance daemon with a posting date before the selected period end.' skip.         
    end.

    if viCubeQueueCnt > 0
    then do:
        assign oiErrorNumbers = oiErrorNumbers + 1.
        put stream sTechOut unformatted 'There are unprocessed records in the cube daemon queue with a posting date before the selected period end.' skip.       
    end.
    if viCubeErrorCnt > 0
    then do:
        assign oiErrorNumbers = oiErrorNumbers + 1.
        put stream sTechOut unformatted 'There are failed queue records in the cube daemon with a posting date before the selected period end.' skip.        
    end.
end. /* MAIN_BLOCK: */

assign oiConCheckLineDetDuration = etime - vdStartEtime.

if oiErrorNumbers > 0
then assign ocConCheckLineDetResult = {&CONCHECKRESULT-WARNING}.

/* to format the total duration time */
assign viMilliSecs = oiConCheckLineDetDuration
       viSecs = TRUNCATE (oiConCheckLineDetDuration / 1000, 0)
       viMilliSecs = viMilliSecs mod 1000
       vcTotalTime = string(viSecs, 'HH:MM:SS')  +  '.'  +  string(viMilliSecs).


/* output summary file */
OUTPUT STREAM sSumOut TO value(icSumFile) APPEND. 
put stream sSumOut unformatted ' ' skip.
PUT STREAM sSumOut unformatted trim({&CONCHECKLINEDETTYPE-DAEMONQUEUE-TR}) skip.
PUT STREAM sSumOut unformatted '-------------' skip.
put stream sSumOut unformatted trim(#T-38'Execution Result':255(510391963)T-38#) + ': ' + ocConCheckLineDetResult skip.

if ocConCheckLineDetResult = {&CONCHECKRESULT-PASSED}
then do:
    put stream sTechOut unformatted 'All daemon queues are processed successfully.' skip.
    put stream sSumOut unformatted 
                trim(#T-48'All daemon queues are processed successfully.':100(29926189)T-48#)
                skip.
end. /* end if ocConCheckLineDetResult = {&CONCHECKRESULT-PASSED} */

/* log passed or failed status */
put stream sTechOut unformatted 'Execution Duration: ' vcTotalTime skip. 
put stream sTechOut unformatted 'Execution Result: ' ocConCheckLineDetResult skip.

put stream sTechOut unformatted '**********************************************************************' skip.

/* close log file stream */
OUTPUT STREAM sTechOut CLOSE. 

/* Check if History Daemon Queue is empty */
if viHistQueueCnt > 0
then do:
    put stream sSumOut unformatted 
        trim(substitute(#T-22'There are unprocessed records in the &1 queue with a posting date before the selected period end.':150(944968527)T-22#,
            {&HISTORYDAEMON-TR}))
        skip.       
end.        
if viHistErrorCnt > 0
then do:
    put stream sSumOut unformatted 
        trim(substitute(#T-47'There are failed queue records in the &1 with a posting date before the selected period end.':200(207483269)T-47#,
            {&HISTORYDAEMON-TR}))
        skip.        
end.
/* Check if CrossCy Daemon Queue is empty */
if viCrossCyQueueCnt > 0 
then do:
    put stream sSumOut unformatted 
        trim(substitute(#T-54'There are unprocessed records in the &1 queue with a posting date before the selected period end.':150(944968527)T-54#,
            {&CROSSCOMPANYDAEMON-TR}))
        skip. 
end.
if viCrossCyErrorCnt > 0 
then do:
    put stream sSumOut unformatted 
        trim(substitute(#T-9'There are failed queue records in the &1 with a posting date before the selected period end.':200(207483269)T-9#,
            {&CROSSCOMPANYDAEMON-TR}))
        skip.        
end.
/* Check if Balance Daemon Queue is empty */
if viBalanceQueueCnt > 0
then do:
    put stream sSumOut unformatted 
        trim(substitute(#T-33'There are unprocessed records in the &1 queue with a posting date before the selected period end.':150(944968527)T-33#,
            {&BALANCEDAEMON-TR}))
        skip.       
end.

if viBalanceErrorCnt > 0
then do:
    put stream sSumOut unformatted 
        trim(substitute(#T-90'There are failed queue records in the &1 with a posting date before the selected period end.':200(207483269)T-90#,
            {&BALANCEDAEMON-TR}))
        skip.        
end.
/* Check if Cube Daemon Queue is empty */
if viCubeQueueCnt > 0
then do:
    put stream sSumOut unformatted 
        trim(substitute(#T-85'There are unprocessed records in the &1 queue with a posting date before the selected period end.':150(944968527)T-85#,
            {&CUBEDAEMON-TR}))
        skip.       
end.

if viCubeErrorCnt > 0
then do:
    put stream sSumOut unformatted 
        trim(substitute(#T-55'There are failed queue records in the &1 with a posting date before the selected period end.':200(207483269)T-55#,
            {&CUBEDAEMON-TR}))
        skip.        
end.

put stream sSumOut unformatted "____________________________________________________________" skip.
OUTPUT STREAM sSumOut CLOSE. 

if oiReturnStatus = -98
then assign oiReturnStatus = 0.