project BLF > class BBaseDaemonProcessor > method SetWorkResult

Description

method to set the result of a processed DaemonQueue instance.
Depending on settings and the availability of messages the instance method with the same name is called in BBaseDeamoneQUeue or writedirect is used.


Parameters


ilSuccesinputlogicalIndication of workresult
iiDaemonQueueIDinputintegerDaemonQueue instance ID
iiDaemonQueuePriorityinputinteger
ocErrorMessageoutputcharacterError Message
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


BLF
method BBaseDaemonProcessor.LoopForWork


program code (program1/bbasedaemonprocessor.p)

assign oiReturnStatus = -98.

/* ===================================================================================================== */
/* In case the daemon is setup (coded) to try to reprocess queues in case of a failure, and there are    */
/* still trials to do, let's do it. We will put the requested time with a delay of 30sec                 */
/* !! Note we are misusign DaemonQueuePriority to keep the number of trials per queueu                   */
/* ===================================================================================================== */
assign vlReprocessQueue = (not ilSucces and vlUseWriteDirectInSetWorkResult = true and viMaxNumberOfRetriesPerQueue > 0 and iiDaemonQueuePriority + 1 < viMaxNumberOfRetriesPerQueue).

if (vlUseWriteDirectInSetWorkResult eq true and not can-find (first tPassMessages)) or vlReprocessQueue
then do:
   
   assign vhFcComponent = vhFcPersistence.
   
   <M-4 run InitTransaction
      (output viFcReturnSuper (oiReturnStatus)) in persistence> 
      
   if viFcReturnSuper ne 0
   then do:
       assign 
           ocErrorMessage = substitute(#T-1'Error (&1) starting a transaction':128(5118)T-1#, string(viFcReturnSuper)).
           oiReturnStatus = viFcReturnSuper.
       return.
   end.

   /* Save date and time in UTC */
   session:timezone = 0.
   
   /* prepare for storing new status of queue record */
   assign
      vcPrepare = "for each fcDaemonQueue where fcDaemonQueue.DaemonQueueID = ":U + string(iiDaemonQueueID)   
      vcFieldList = "DaemonQueueLockedProcess,DaemonQueueEndDate,DaemonQueueEndTime,DaemonQueueStatus":U
      vcFieldListDataTypes = "i,t,i,c":U
      vcValueList= "0":U + chr(02) + string(today) + chr(02) + string(time) + chr(02) + 
          if ilSucces 
          then {&DAEMONQUEUESTATUS-PROCESSEDOK}
          else
          if vlReprocessQueue
          then {&DAEMONQUEUESTATUS-WAITING}
          else {&DAEMONQUEUESTATUS-PROCESSEDERR}.
   
   /* or reprocessing */
   if vlReprocessQueue
   then do :
        assign vcFieldList          = vcFieldList          + ",DaemonQueuePriority,DaemonQueueReqStartDate,DaemonQueueReqStartTime"
               vcFieldListDataTypes = vcFieldListDataTypes + ",i,t,i":U
               vcValueList          = vcValueList          + chr(02)+ string(iiDaemonQueuePriority + 1) + chr(02) + string(today) + chr(02) + string(time + 30).
   end.

   session:timezone = viTimeOffset.
   
   /* or deleting successfully process item */
   if ilSucces and (vlDoIKeepProcessedItems eq false)
   then do:
       assign 
           vcfieldList = "":U
           vcFieldListDataTypes = "":U
           vcValueList = "":U.
   end.
   
   /* execute the prepared change */
   <M-5 run WriteDirect
      (input  'fcDaemonQueue':U (icTableName), 
       input  vcPrepare (icPrepare), 
       input  vcFieldList (icFieldList), 
       input  vcFieldListDataTypes (icFieldListDataTypes), 
       input  vcValueList (icAbsolute), 
       input  '':U (icIncremental), 
       input  {&TARGETPROCEDURE} (ihClass), 
       input  vcFcDaemonLogin (icUserLogin), 
       output viFcReturnSuper (oiReturnStatus)) in persistence>

   if viFcReturnSuper ne 0
   then do:
       assign 
           ocErrorMessage = substitute(#T-2'Writedirect failed with error code &1':128(5119)T-2#, string(viFcReturnSuper))
           oiReturnStatus = viFcReturnSuper.
       <M-6 run AbortTransaction
          (output viFcReturnSuper (oiReturnStatus)) in persistence>
       return.
   end.
 
   <M-7 run CommitTransaction
       (output viFcReturnSuper (oiReturnStatus)) in persistence>   
   if viFcReturnSuper ne 0
   then do:
   
       assign 
           oiReturnStatus = viFcReturnSuper
           ocErrorMessage = substitute(#T-3'Commit transaction failed with error code &1':128(5120)T-3#, string(viFcReturnSuper)).
       return.
   end.
  
end.
else do:
    /*  redirect to the instance method in BBaseDaemonQueue */
    <M-8 run SetWorkResult
       (input  vlDoIKeepProcessedItems (ilKeepProcessedOKItems), 
        input  ilSucces (ilSuccess), 
        input  iiDaemonQueueID (iiDaemonQueueId), 
        input  tPassMessages (tResultMessages), 
        output ocErrorMessage (ocErrorMessage), 
        output oiReturnStatus (oiReturnStatus)) in BBaseDaemonQueue>
        if oiReturnStatus ne 0 then return.
end.

if oiReturnStatus eq -98
then assign oiReturnStatus = 0.