Description
Initialize the daemon.
In this method everything is prepared for the proper functioning of the daemon.
Parameters
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
BLF
program code (program1/bbasedaemonprocessor.p)
assign oiReturnStatus = -98.
/* ================================================================= */
/* Determine the log file and the process id of the daemon */
/* ================================================================= */
assign vcFcDaemonLogFile = session:temp-dir + vcFcDaemonName + "Default.log":U.
<M-60 run Main (input viSessionID (iiSessionId)) in TDaemonUtility>
<M-75 run GetHostName (output vcFcDaemonProcessHostName (ocHostName)) in TDaemonUtility>
run gipr_DeleteProcedure in vhFcComponent.
delete procedure vhFcComponent.
if OPSYS = "UNIX":U
then do :
INPUT stream spid THROUGH "echo $PPID":U.
IMPORT stream spid vcTemp.
INPUT stream spid CLOSE.
viFcDaemonProcessId = 0.
assign viFcDaemonProcessId = integer(vcTemp) no-error.
if viFcDaemonProcessId = 0
then do:
create buffer vhConnBuffer for table "_MyConnection" in widget-pool "non-persistent" no-error.
if vhConnBuffer <> ?
then do:
vhConnBuffer:find-first ("",no-lock).
if vhConnBuffer:available
then viFcDaemonProcessId = vhConnBuffer::_MyConn-Pid.
delete object vhConnBuffer.
end.
end.
if viFcDaemonProcessId = 0
then do:
oiReturnStatus = -5.
<M-61 run SetMessage
(input 'Failed to retrieve process ID.' (icMessage),
input '' (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'S' (icType),
input 1 (iiSeverity),
input '' (icRowid),
input 'BLF-901832':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBaseDaemonProcessor>
return.
end.
end.
else do:
<M-11 run Main () in Win32Lib>
viFcDaemonProcessId = <M-12 GetCurrentProcess () in Win32Lib>.
run gipr_DeleteProcedure in vhFcComponent.
delete procedure vhFcComponent.
end.
/* ================================================================= */
/* Put the date and numeric format to the correct values. */
/* ================================================================= */
assign session:date-format = 'mdy':U
session:NUMERIC-FORMAT = 'american':U.
/* ================================================================= */
/* We cannot access a BC in the application without being connected */
/* to the database. We force the database to be connected by */
/* executing a query; if the database is not connected it will be */
/* connected by this code (using server.xml). */
/* ================================================================= */
<Q-2 run DaemonInfo (all) (Read) (NoCache) (input 0, (DaemonId)
input vcFcDaemonName, (DaemonName)
input '', (DaemonStatus)
input '', (DaemonStatusDiffersFrom)
output dataset tqDaemonInfo) in BBaseDaemon >
find first tqDaemonInfo
no-lock no-error.
if not available tqDaemonInfo
then do :
<M-6 run SetMessageInDaemonLog
(input 'DaemonProcessor.Initialize; ':U + #T-9'Error: Daemon is not yet configured. Unable to run.':255(636627013)T-9# + string(viFcReturnSuper) (icMessage),
output viFcReturnSuper (oiReturnStatus)) in BBaseDaemonProcessor>
assign oiReturnStatus = -3.
return.
end. /* if not can-find (first tqDaemonPrim) */
assign vcTemp = replace(tqDaemonInfo.tcDaemonLogFile,"~\":U,"/":U).
if num-entries(vcTemp,"/") > 1
then do:
ENTRY(NUM-ENTRIES(vcTemp,"/"),vcTemp,"/") = "".
file-info:file-name = vcTemp.
if file-info:file-type = "DRW":U
then vcFcDaemonLogFile = tqDaemonInfo.tcDaemonLogFile.
end.
else vcFcDaemonLogFile = tqDaemonInfo.tcDaemonLogFile.
/* ================================================================= */
/* Log that the daemon is starting/stopping */
/* ================================================================= */
<M-13 run SetMessageInDaemonLog
(input 'DaemonProcessor.Initialize; ':U + #T-72'Start requested action:':255(91262731)T-72# + (if vlFcStopDaemon then #T-33'Stop':20(8577)T-33# else #T-62'Start':20(8575)T-62#) (icMessage),
output viFcReturnSuper (oiReturnStatus)) in BBaseDaemonProcessor>
assign vcFcDaemonLogin = tqDaemonInfo.tcDaemonLogin
viFcDaemonInterval = tqDaemonInfo.tiDaemonInterval
viFcDaemonId = tqDaemonInfo.tiDaemonId
vlDoIKeepProcessedItems = tqDaemonInfo.tlDaemonKeepProcessedOKItems.
/*Decode the password before using it*/
assign vhFcComponent = ?.
<M-14 run MainBlock () in TCrypt>
<M-15 run DecryptString
(input tqDaemonInfo.tcDaemonPassword (icInputString),
output vcFcDaemonPassword (ocOutputString),
output viFcReturnSuper (oiReturnStatus)) in TCrypt>
run gipr_DeleteProcedure in vhFcComponent.
delete procedure vhFcComponent.
/* ================================================================= */
/* Start the business components that contain all functions to */
/* update the DB. */
/* ================================================================= */
<M-7 run StartDaemonComponent (output vhBBaseDaemonInst (ohDaemon),
output vhBBaseDaemonQueueInst (ohDaemonQueue),
output viFcReturnSuper (oiReturnStatus)) in BBaseDaemonProcessor>
if viFcReturnSuper <> 0
then do :
<M-10 run SetMessageInDaemonLog
(input 'DaemonProcessor.Initialize; ':U + #T-30'Error: Unable to start daemon component.':255(400084972)T-30# + string(vifcreturnSuper) (icMessage),
output viFcReturnSuper (oiReturnStatus)) in BBaseDaemonProcessor>
assign oiReturnStatus = viFcReturnSuper.
return.
end.
empty temp-table tqDaemonInfo.
assign oiReturnStatus = 0.