project BLF > class BBaseDaemonQueue > method LockWorkItem
Description
Lock a certain record in the fcDaemonQueue.
Locking means being able to set the "LockedProcess" field on a certain value.
Parameters
iiDaemonQueueId | input | integer | ID of the daemonqueue record that needs to be locked |
iiProcessId | input | integer | The process number of the daemonprocessor that wants to lock the record. |
ocMessage | output | character | Message produced by the locking of 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/bbasedaemonqueue.p)
assign oiReturnStatus = -98.
/* ================================================================================================== */
/* 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-1 run DataLoad
(input '' (icRowids),
input iiDaemonQueueId (icPkeys),
input '' (icObjectIds),
input '' (icFreeform),
input false (ilKeepPrevious),
output viFcReturnSuper (oiReturnStatus)) in BBaseDaemonQueue>
/* Queue record does not exist any more */
if viFcReturnSuper = -4
then do:
assign ocMessage = "":U
oiReturnStatus = -111.
return.
end.
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
assign ocMessage = substitute(#T-6'Unable to load the instance data for daemon ID (&1).':120(46)T-6#,string(iiDaemonQueueId)).
return.
end.
find first tfcDaemonQueue no-error.
if not available tfcDaemonQueue
then do :
assign ocMessage = substitute(#T-7'No record available after instance data load for daemon ID (&1).':120(47)T-7#,string(iiDaemonQueueId))
oiReturnStatus = -3.
return.
end.
/* assign a particular return value because daemonprocessor knows what it means */
if tfcDaemonQueue.DaemonQueueLockedProcess <> 0 or tfcDaemonQueue.DaemonQueueStatus <> {&DAEMONQUEUESTATUS-WAITING}
then do:
assign ocMessage = "":U
oiReturnStatus = -111.
return.
end.
else do :
/* Save date and time in UTC */
session:timezone = 0.
assign tfcDaemonQueue.DaemonQueueLockedProcess = iiProcessId
tfcDaemonQueue.DaemonQueueStartDate = today
tfcDaemonQueue.DaemonQueueStartTime = time
tfcDaemonQueue.DaemonQueueStatus = {&DAEMONQUEUESTATUS-INPROCESS}
tfcDaemonQueue.tc_Status = "C":U.
session:timezone = viTimeOffset.
<M-3 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BBaseDaemonQueue>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper >= 0
then do:
<M-4 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BBaseDaemonQueue>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper >= 0
then do:
<M-5 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BBaseDaemonQueue>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper >= 0
then assign olLocked = true.
end.
end.
if not olLocked
then assign ocMessage = substitute(#T-9'Unable to lock the daemon queue (&1).':120(49)T-9#,string (iiDaemonQueueId)).
if viFcReturnSuper < 0
then return.
end.
if oiReturnStatus = -98
then assign oiReturnStatus = 0.