Description
Method to lock the work item that will be processed by the queue.
Parameters
iiDaemonQueueID | input | integer | ID of the Daemonqueue record that needs to be locked. |
iiProcessID | input | integer | Process ID of the daemonprocessor that wants to lock the record. |
ocMessage | output | character | Message produced when locking the work item |
olLocked | output | logical | Indication whether the record could be locked or not. |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
BLF
program code (program1/bbasedaemonprocessor.p)
if vlUseWriteDirectInLockWorkItem
then do:
assign
vhFcComponent = vhFcPersistence
vcPrepare = "for each fcDaemonQueue where fcDaemonQueue.DaemonQueueID = ":U + string(iiDaemonQueueID).
/* ================================================================================================== */
/* We need to check if this queue is not taken by another process */
/* For this, the following must be valid: the record must still exist, the DaemonQueueLockedProcess=0 */
/* and DaemonQueueStatus=WAITING */
/* If the queue would be invalid, we return a -111 error status as we don't want to get this reported */
/* ================================================================================================== */
<M-5 run ReadDirect
(input 'fcDaemonQueue':U (icTableName),
input vcPrepare (icPrepare),
input 'DaemonQueueLockedProcess,DaemonQueueStatus':U (icFieldList),
output vcDaemonQueueInfo (ocValueList),
input {&TARGETPROCEDURE} (ihClass),
output viFcReturnSuper (oiReturnStatus)) in persistence>
/* Queue does not exist any more */
if viFcReturnSuper = -4
then do:
assign ocMessage = "":U
oiReturnStatus = -111.
return.
end.
if viFcReturnSuper ne 0
then do:
assign ocMessage = substitute(#T-1'Read direct failed with error number &1':128(5117)T-1#, string (viFcReturnSuper))
oiReturnStatus = viFcReturnSuper.
return.
end.
if num-entries (vcDaemonQueueInfo,chr(2)) = 2
then do:
if entry (2,vcDaemonQueueInfo,chr(2)) <> {&DAEMONQUEUESTATUS-WAITING} or
(entry (1,vcDaemonQueueInfo,chr(2)) <> '0' and
entry (1,vcDaemonQueueInfo,chr(2)) <> ? and
entry (1,vcDaemonQueueInfo,chr(2)) <> '')
then do:
assign ocMessage = "":U
oiReturnStatus = -111.
return.
end.
end. /* if num-entries */
<M-6 run InitTransaction
(output viFcReturnSuper (oiReturnStatus)) in persistence>
if viFcReturnSuper ne 0
then do:
assign
ocMessage = substitute(#T-2'Error (&1) starting a transaction':128(5118)T-2#, string(viFcReturnSuper)).
oiReturnStatus = viFcReturnSuper.
return.
end.
/* Save date and time in UTC */
session:timezone = 0.
assign
vcFieldList = "DaemonQueueLockedProcess,DaemonQueueStartDate,DaemonQueueStartTime,DaemonQueueStatus":U
vcFieldListDataTypes = "i,t,i,c":U
vcValueList= string(iiProcessID) + chr(02) + string(today) + chr(02) + string(integer(time)) + chr(02) + {&DAEMONQUEUESTATUS-INPROCESS}.
<M-7 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>
session:timezone = viTimeOffset.
if viFcReturnSuper ne 0
then do:
assign
oiReturnStatus = viFcReturnSuper
ocmessage = substitute(#T-3'Writedirect failed with error code &1':128(5119)T-3#, string(viFcReturnSuper)).
<M-8 run AbortTransaction
(output viFcReturnSuper (oiReturnStatus)) in persistence>
return.
end.
<M-9 run CommitTransaction
(output viFcReturnSuper (oiReturnStatus)) in persistence>
if viFcReturnSuper ne 0
then do:
assign
oiReturnStatus = viFcReturnSuper
ocmessage = substitute(#T-4'Commit transaction failed with error code &1':128(5120)T-4#, string(viFcReturnSuper)).
return.
end.
assign olLocked = true.
end.
else do:
/* use this method as a stub ...*/
<M-10 run LockWorkItem
(input iiDaemonQueueID (iiDaemonQueueId),
input iiProcessID (iiProcessId),
output ocMessage (ocMessage),
output olLocked (olLocked),
output oiReturnStatus (oiReturnStatus)) in BBaseDaemonQueue>
end.