|
|
|
@ -40,9 +40,10 @@ Equ Comma$ to ','
|
|
|
|
|
Common /ServiceServices/ Unused1@, Unused2@, Unused3@, Unused4@, Unused5@, Unused6@, Unused7@, Unused8@, Unused9@, Unused10@
|
|
|
|
|
|
|
|
|
|
Declare function Service_Services, Memory_Services, SRP_List, SRP_FastArray, SRP_Array, Database_Services, Datetime
|
|
|
|
|
Declare function GetTickCount, SRP_Decode, RTI_CreateGuid, UCase, Environment_services, Logging_Services
|
|
|
|
|
Declare function GetTickCount, SRP_Decode, RTI_CreateGuid, UCase, Environment_services, Logging_Services,
|
|
|
|
|
Declare function SRP_TCPClient
|
|
|
|
|
Declare subroutine Service_Services, Memory_Services, SRP_List, SRP_FastArray, RList, Set_Status, Database_Services
|
|
|
|
|
Declare Subroutine Yield, WinYield, Sleepery, Btree.Extract, Logging_Services, obj_Notes
|
|
|
|
|
Declare Subroutine Yield, WinYield, Sleepery, Btree.Extract, Logging_Services, obj_Notes, SRP_TCPClient
|
|
|
|
|
|
|
|
|
|
LogPath = Environment_Services('GetApplicationRootPath') : '\LogFiles\ProcQueue'
|
|
|
|
|
LogDate = Oconv(Date(), 'D4/')
|
|
|
|
@ -166,104 +167,145 @@ end service
|
|
|
|
|
|
|
|
|
|
Service ProcessProcedureQueue()
|
|
|
|
|
|
|
|
|
|
// Loop through the procedure queue until we can find a process request that is not yet locked
|
|
|
|
|
// (i.e., already being crunched on by another engine). Process that one request and then end.
|
|
|
|
|
Open 'PROC_QUEUE' to hProcQueue then
|
|
|
|
|
Select hProcQueue
|
|
|
|
|
EOF = False$
|
|
|
|
|
Done = False$
|
|
|
|
|
Loop
|
|
|
|
|
ReadNext RequestKeyID else EOF = True$
|
|
|
|
|
Until EOF or Done
|
|
|
|
|
Lock hProcQueue, RequestKeyID then
|
|
|
|
|
DeleteRequest = True$
|
|
|
|
|
Server = Environment_Services('GetServer')
|
|
|
|
|
Done = True$
|
|
|
|
|
Database_Services('GetKeyIDLock', 'PROC_QUEUE', RequestKeyId)
|
|
|
|
|
RequestRow = Database_Services('ReadDataRow', 'PROC_QUEUE', RequestKeyID)
|
|
|
|
|
If RequestRow NE '' then
|
|
|
|
|
Procedure = RequestRow<PROC_QUEUE.PROC_NAME$>
|
|
|
|
|
Procedure = UCase(Procedure)
|
|
|
|
|
Params = RequestRow<PROC_QUEUE.PARAMS$>
|
|
|
|
|
If Procedure NE '' then
|
|
|
|
|
Dim ProcParams(12)
|
|
|
|
|
For each Param in Params using @VM setting pPos
|
|
|
|
|
ProcParams(pPos) = Param
|
|
|
|
|
Next Param
|
|
|
|
|
NumArguments = DCount(Params, @VM)
|
|
|
|
|
|
|
|
|
|
Begin Case
|
|
|
|
|
Case NumArguments EQ 0 ; Call @Procedure()
|
|
|
|
|
Case NumArguments EQ 1 ; Call @Procedure(ProcParams(1))
|
|
|
|
|
Case NumArguments EQ 2 ; Call @Procedure(ProcParams(1), ProcParams(2))
|
|
|
|
|
Case NumArguments EQ 3 ; Call @Procedure(ProcParams(1), ProcParams(2), ProcParams(3))
|
|
|
|
|
Case NumArguments EQ 4 ; Call @Procedure(ProcParams(1), ProcParams(2), ProcParams(3), ProcParams(4))
|
|
|
|
|
Case NumArguments EQ 5 ; Call @Procedure(ProcParams(1), ProcParams(2), ProcParams(3), ProcParams(4), ProcParams(5))
|
|
|
|
|
Case NumArguments EQ 6 ; Call @Procedure(ProcParams(1), ProcParams(2), ProcParams(3), ProcParams(4), ProcParams(5), ProcParams(6))
|
|
|
|
|
Case NumArguments EQ 7 ; Call @Procedure(ProcParams(1), ProcParams(2), ProcParams(3), ProcParams(4), ProcParams(5), ProcParams(6), ProcParams(7))
|
|
|
|
|
Case NumArguments EQ 8 ; Call @Procedure(ProcParams(1), ProcParams(2), ProcParams(3), ProcParams(4), ProcParams(5), ProcParams(6), ProcParams(7), ProcParams(8))
|
|
|
|
|
Case NumArguments EQ 9 ; Call @Procedure(ProcParams(1), ProcParams(2), ProcParams(3), ProcParams(4), ProcParams(5), ProcParams(6), ProcParams(7), ProcParams(8), ProcParams(9))
|
|
|
|
|
Case NumArguments EQ 10 ; Call @Procedure(ProcParams(1), ProcParams(2), ProcParams(3), ProcParams(4), ProcParams(5), ProcParams(6), ProcParams(7), ProcParams(8), ProcParams(9), ProcParams(10))
|
|
|
|
|
Case NumArguments EQ 11 ; Call @Procedure(ProcParams(1), ProcParams(2), ProcParams(3), ProcParams(4), ProcParams(5), ProcParams(6), ProcParams(7), ProcParams(8), ProcParams(9), ProcParams(10), ProcParams(11))
|
|
|
|
|
Case Otherwise$
|
|
|
|
|
Error_Services('Add', 'Error in ':Service:' service. More than 11 arguments are not currently supported.')
|
|
|
|
|
End Case
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
Swap @VM with ',' in Params
|
|
|
|
|
LogData = LoggingDTM
|
|
|
|
|
LogData<2> = Server
|
|
|
|
|
LogData<3> = RequestKeyId
|
|
|
|
|
LogData<4> = Procedure
|
|
|
|
|
LogData<5> = Params
|
|
|
|
|
ErrCode = ''
|
|
|
|
|
If ( Get_Status(ErrCode) or Error_Services('HasError') ) then
|
|
|
|
|
NumAttempts = RequestRow<PROC_QUEUE.NUM_ATTEMPTS$> + 1
|
|
|
|
|
ErrorMessage = Error_Services('GetMessage')
|
|
|
|
|
If NumAttempts LT 3 then
|
|
|
|
|
DeleteRequest = False$
|
|
|
|
|
RequestRow<PROC_QUEUE.NUM_ATTEMPTS$> = NumAttempts
|
|
|
|
|
RequestRow<PROC_QUEUE.LAST_ATTEMPT_DTM$> = Datetime()
|
|
|
|
|
RequestRow<PROC_QUEUE.ERROR$> = 'Error_Services error message: ':ErrorMessage:' Get_Status error code: ':ErrCode
|
|
|
|
|
Database_Services('WriteDataRow', 'PROC_QUEUE', RequestKeyId, RequestRow, True$, False$, False$)
|
|
|
|
|
end else
|
|
|
|
|
// Notify OI_SYSADMIN group
|
|
|
|
|
Recipients = ''
|
|
|
|
|
SentFrom = 'SYSTEM'
|
|
|
|
|
Subject = 'Background Procedure Queue Error'
|
|
|
|
|
Message = OConv(Datetime(), 'DT2/^H')
|
|
|
|
|
Message<2> = 'Error on server ':Server
|
|
|
|
|
Message<3> = 'Stored Procedure: ':Procedure
|
|
|
|
|
StatCodes = 'Parameters: ':Params
|
|
|
|
|
Message<4> = 'Error_Services error message: ':ErrorMessage
|
|
|
|
|
Message<5> = 'Get_Status error code: ':ErrCode
|
|
|
|
|
Swap @FM with \0D0A\ in Message
|
|
|
|
|
AttachWindow = ''
|
|
|
|
|
AttachKey = ''
|
|
|
|
|
SendToGroup = 'OI_SYSADMIN'
|
|
|
|
|
Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
|
|
|
|
|
obj_Notes('Create',Parms)
|
|
|
|
|
|
|
|
|
|
// Move request to PROC_QUEUE_FAILED
|
|
|
|
|
RequestRow<PROC_QUEUE.NUM_ATTEMPTS$> = NumAttempts
|
|
|
|
|
RequestRow<PROC_QUEUE.LAST_ATTEMPT_DTM$> = Datetime()
|
|
|
|
|
RequestRow<PROC_QUEUE.ERROR$> = 'Error_Services error message: ':ErrorMessage:'Get_Status error code: ':ErrCode
|
|
|
|
|
Database_Services('WriteDataRow', 'PROC_QUEUE_FAILED', RequestKeyId, RequestRow, True$, False$, False$)
|
|
|
|
|
end
|
|
|
|
|
LogData<6> = 'Failed'
|
|
|
|
|
LogData<7> = 'Error_Services error message: ':ErrorMessage:' Get_Status error code: ':ErrCode
|
|
|
|
|
end else
|
|
|
|
|
LogData<6> = 'Success'
|
|
|
|
|
end
|
|
|
|
|
Logging_Services('AppendLog', objLog, LogData, @RM, @FM)
|
|
|
|
|
end
|
|
|
|
|
If DeleteRequest then
|
|
|
|
|
Database_Services('DeleteDataRow', 'PROC_QUEUE', RequestKeyId, True$, False$)
|
|
|
|
|
hSysLists = Database_Services('GetTableHandle', 'SYSLISTS')
|
|
|
|
|
Lock hSysLists, ServiceKeyID then
|
|
|
|
|
ServerIP = Environment_Services('GetApplicationRootIP')
|
|
|
|
|
ServerPort = Environment_Services('GetServiceManagerPort')
|
|
|
|
|
Convert '\' to '' in ServerIP
|
|
|
|
|
Open 'PROC_QUEUE' to hProcQueue then
|
|
|
|
|
Select hProcQueue
|
|
|
|
|
EOF = False$
|
|
|
|
|
Loop
|
|
|
|
|
ReadNext RequestKeyID else EOF = True$
|
|
|
|
|
Until EOF
|
|
|
|
|
TcpClientHandle = 0
|
|
|
|
|
If SRP_TcpClient(TcpClientHandle, 'CONNECT', ServerIP, ServerPort) then
|
|
|
|
|
Command = 'RUN SERVICE_SERVICES "ProcessRequest", ':Quote(RequestKeyID)
|
|
|
|
|
SRP_TcpClient(TcpClientHandle, 'SEND_SES', Command)
|
|
|
|
|
SRP_TcpClient(TcpClientHandle, 'CLOSE_SES')
|
|
|
|
|
end
|
|
|
|
|
Unlock hProcQueue, RequestKeyID else Null
|
|
|
|
|
end
|
|
|
|
|
Repeat
|
|
|
|
|
end
|
|
|
|
|
Repeat
|
|
|
|
|
end
|
|
|
|
|
Unlock hSysLists, ServiceKeyID else Null
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end service
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Service ProcessRequest(RequestKeyID)
|
|
|
|
|
|
|
|
|
|
If RequestKeyID NE '' then
|
|
|
|
|
DeleteRequest = True$
|
|
|
|
|
Server = Environment_Services('GetServer')
|
|
|
|
|
Done = True$
|
|
|
|
|
If RowExists('PROC_QUEUE', RequestKeyID) then
|
|
|
|
|
RequestRow = Database_Services('ReadDataRow', 'PROC_QUEUE', RequestKeyID)
|
|
|
|
|
If RequestRow NE '' then
|
|
|
|
|
Procedure = RequestRow<PROC_QUEUE.PROC_NAME$>
|
|
|
|
|
Procedure = UCase(Procedure)
|
|
|
|
|
Params = RequestRow<PROC_QUEUE.PARAMS$>
|
|
|
|
|
If Procedure NE '' then
|
|
|
|
|
Dim ProcParams(12)
|
|
|
|
|
For each Param in Params using @VM setting pPos
|
|
|
|
|
ProcParams(pPos) = Param
|
|
|
|
|
Next Param
|
|
|
|
|
NumArguments = DCount(Params, @VM)
|
|
|
|
|
|
|
|
|
|
Begin Case
|
|
|
|
|
Case NumArguments EQ 0 ; Call @Procedure()
|
|
|
|
|
Case NumArguments EQ 1 ; Call @Procedure(ProcParams(1))
|
|
|
|
|
Case NumArguments EQ 2 ; Call @Procedure(ProcParams(1), ProcParams(2))
|
|
|
|
|
Case NumArguments EQ 3 ; Call @Procedure(ProcParams(1), ProcParams(2), ProcParams(3))
|
|
|
|
|
Case NumArguments EQ 4 ; Call @Procedure(ProcParams(1), ProcParams(2), ProcParams(3), ProcParams(4))
|
|
|
|
|
Case NumArguments EQ 5 ; Call @Procedure(ProcParams(1), ProcParams(2), ProcParams(3), ProcParams(4), ProcParams(5))
|
|
|
|
|
Case NumArguments EQ 6 ; Call @Procedure(ProcParams(1), ProcParams(2), ProcParams(3), ProcParams(4), ProcParams(5), ProcParams(6))
|
|
|
|
|
Case NumArguments EQ 7 ; Call @Procedure(ProcParams(1), ProcParams(2), ProcParams(3), ProcParams(4), ProcParams(5), ProcParams(6), ProcParams(7))
|
|
|
|
|
Case NumArguments EQ 8 ; Call @Procedure(ProcParams(1), ProcParams(2), ProcParams(3), ProcParams(4), ProcParams(5), ProcParams(6), ProcParams(7), ProcParams(8))
|
|
|
|
|
Case NumArguments EQ 9 ; Call @Procedure(ProcParams(1), ProcParams(2), ProcParams(3), ProcParams(4), ProcParams(5), ProcParams(6), ProcParams(7), ProcParams(8), ProcParams(9))
|
|
|
|
|
Case NumArguments EQ 10 ; Call @Procedure(ProcParams(1), ProcParams(2), ProcParams(3), ProcParams(4), ProcParams(5), ProcParams(6), ProcParams(7), ProcParams(8), ProcParams(9), ProcParams(10))
|
|
|
|
|
Case NumArguments EQ 11 ; Call @Procedure(ProcParams(1), ProcParams(2), ProcParams(3), ProcParams(4), ProcParams(5), ProcParams(6), ProcParams(7), ProcParams(8), ProcParams(9), ProcParams(10), ProcParams(11))
|
|
|
|
|
Case Otherwise$
|
|
|
|
|
Error_Services('Add', 'Error in ':Service:' service. More than 11 arguments are not currently supported.')
|
|
|
|
|
End Case
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
Swap @VM with ',' in Params
|
|
|
|
|
LogData = LoggingDTM
|
|
|
|
|
LogData<2> = Server
|
|
|
|
|
LogData<3> = RequestKeyId
|
|
|
|
|
LogData<4> = Procedure
|
|
|
|
|
LogData<5> = Params
|
|
|
|
|
ErrCode = ''
|
|
|
|
|
If ( Get_Status(ErrCode) or Error_Services('HasError') ) then
|
|
|
|
|
NumAttempts = RequestRow<PROC_QUEUE.NUM_ATTEMPTS$> + 1
|
|
|
|
|
ErrorMessage = Error_Services('GetMessage')
|
|
|
|
|
If NumAttempts LT 3 then
|
|
|
|
|
DeleteRequest = False$
|
|
|
|
|
RequestRow<PROC_QUEUE.NUM_ATTEMPTS$> = NumAttempts
|
|
|
|
|
RequestRow<PROC_QUEUE.LAST_ATTEMPT_DTM$> = Datetime()
|
|
|
|
|
RequestRow<PROC_QUEUE.ERROR$> = 'Error_Services error message: ':ErrorMessage:' Get_Status error code: ':ErrCode
|
|
|
|
|
Database_Services('WriteDataRow', 'PROC_QUEUE', RequestKeyId, RequestRow, True$, False$, False$)
|
|
|
|
|
end else
|
|
|
|
|
// Notify OI_SYSADMIN group
|
|
|
|
|
Recipients = ''
|
|
|
|
|
SentFrom = 'SYSTEM'
|
|
|
|
|
Subject = 'Background Procedure Queue Error'
|
|
|
|
|
Message = OConv(Datetime(), 'DT2/^H')
|
|
|
|
|
Message<2> = 'Error on server ':Server
|
|
|
|
|
Message<3> = 'Stored Procedure: ':Procedure
|
|
|
|
|
StatCodes = 'Parameters: ':Params
|
|
|
|
|
Message<4> = 'Error_Services error message: ':ErrorMessage
|
|
|
|
|
Message<5> = 'Get_Status error code: ':ErrCode
|
|
|
|
|
Swap @FM with \0D0A\ in Message
|
|
|
|
|
AttachWindow = ''
|
|
|
|
|
AttachKey = ''
|
|
|
|
|
SendToGroup = 'OI_SYSADMIN'
|
|
|
|
|
Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
|
|
|
|
|
obj_Notes('Create',Parms)
|
|
|
|
|
// Move request to PROC_QUEUE_FAILED
|
|
|
|
|
RequestRow<PROC_QUEUE.NUM_ATTEMPTS$> = NumAttempts
|
|
|
|
|
RequestRow<PROC_QUEUE.LAST_ATTEMPT_DTM$> = Datetime()
|
|
|
|
|
RequestRow<PROC_QUEUE.ERROR$> = 'Error_Services error message: ':ErrorMessage:'Get_Status error code: ':ErrCode
|
|
|
|
|
Database_Services('WriteDataRow', 'PROC_QUEUE_FAILED', RequestKeyId, RequestRow, True$, False$, False$)
|
|
|
|
|
end
|
|
|
|
|
LogData<6> = 'Failed'
|
|
|
|
|
LogData<7> = 'Error_Services error message: ':ErrorMessage:' Get_Status error code: ':ErrCode
|
|
|
|
|
end else
|
|
|
|
|
LogData<6> = 'Success'
|
|
|
|
|
end
|
|
|
|
|
Logging_Services('AppendLog', objLog, LogData, @RM, @FM)
|
|
|
|
|
end else
|
|
|
|
|
DeleteRequest = False$
|
|
|
|
|
// Failed to read request record.
|
|
|
|
|
ErrorMessage = Error_Services('GetMessage')
|
|
|
|
|
LogData = LoggingDTM
|
|
|
|
|
LogData<2> = Server
|
|
|
|
|
LogData<3> = RequestKeyId
|
|
|
|
|
LogData<4> = ''
|
|
|
|
|
LogData<5> = ''
|
|
|
|
|
LogData<6> = 'Failed'
|
|
|
|
|
LogData<7> = 'Failed to read request record. Error_Services error message: ':ErrorMessage
|
|
|
|
|
ErrCode = ''
|
|
|
|
|
Logging_Services('AppendLog', objLog, LogData, @RM, @FM)
|
|
|
|
|
// Notify OI_SYSADMIN group
|
|
|
|
|
Recipients = ''
|
|
|
|
|
SentFrom = 'SYSTEM'
|
|
|
|
|
Subject = 'Background Procedure Queue Error'
|
|
|
|
|
Message = OConv(Datetime(), 'DT2/^H')
|
|
|
|
|
Message<2> = 'Error on server ':Server
|
|
|
|
|
Message<3> = 'Failed to read request record. Error_Services error message: ':ErrorMessage
|
|
|
|
|
Swap @FM with \0D0A\ in Message
|
|
|
|
|
AttachWindow = ''
|
|
|
|
|
AttachKey = ''
|
|
|
|
|
SendToGroup = 'OI_SYSADMIN'
|
|
|
|
|
Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
|
|
|
|
|
obj_Notes('Create',Parms)
|
|
|
|
|
end
|
|
|
|
|
If DeleteRequest then
|
|
|
|
|
Database_Services('DeleteDataRow', 'PROC_QUEUE', RequestKeyId, True$, False$)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end service
|
|
|
|
|
|
|
|
|
|