Modified copy and delete record to sql routines to lock the queue record before attempting to prevent long running copy or delete calls form being processed more than once and wasting resources.
This commit is contained in:
@ -1,6 +1,4 @@
|
||||
Compile subroutine Copy_Backlog_Records_To_SQL(VOID)
|
||||
#pragma precomp SRP_PreCompiler
|
||||
|
||||
/*****************************************************************************\
|
||||
This is a utility function. For each record found in SQL_BACKLOG, it makes
|
||||
sure the identified record is copied to SQL. Then the backlog record is
|
||||
@ -10,12 +8,14 @@ Compile subroutine Copy_Backlog_Records_To_SQL(VOID)
|
||||
-------
|
||||
08/10/2010 KRF Original Programmer
|
||||
\*****************************************************************************/
|
||||
|
||||
#pragma precomp SRP_PreCompiler
|
||||
$Insert APP_INSERTS
|
||||
|
||||
Declare subroutine Copy_Record_To_SQL, Delete_Record_From_SQL, SRP_TcpClient, Copy_Pending_Records_To_Sql
|
||||
Declare function GetTickCount, Database_Services, SRP_TcpClient, Datetime, Environment_Services
|
||||
|
||||
Main:
|
||||
|
||||
hSysLists = Database_Services('GetTableHandle', 'SYSLISTS')
|
||||
Lock hSysLists, 'Copy_Backlog_Records_To_SQL' then
|
||||
|
||||
@ -86,8 +86,9 @@ Lock hSysLists, 'Copy_Backlog_Records_To_SQL' then
|
||||
If Skip EQ False$ then
|
||||
TcpClientHandle = 0
|
||||
ServerIP = Environment_Services('GetApplicationRootIP')
|
||||
ServerPort = Environment_Services('GetScrapeServerPort')
|
||||
Convert '\' to '' in ServerIP
|
||||
If SRP_TcpClient(TcpClientHandle, 'CONNECT', ServerIP, '20779') then
|
||||
If SRP_TcpClient(TcpClientHandle, 'CONNECT', ServerIP, ServerPort) then
|
||||
SRP_TcpClient(TcpClientHandle, 'SEND_SES', Command)
|
||||
SRP_TcpClient(TcpClientHandle, 'CLOSE_SES')
|
||||
end
|
||||
@ -101,4 +102,3 @@ end
|
||||
|
||||
Return
|
||||
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
Compile subroutine Copy_Pending_Records_To_SQL(VOID)
|
||||
#pragma precomp SRP_PreCompiler
|
||||
|
||||
/*****************************************************************************\
|
||||
This is a utility function. For each record found in SQL_PENDING, it makes
|
||||
sure the identified record is copied to SQL.
|
||||
@ -9,19 +7,25 @@ Compile subroutine Copy_Pending_Records_To_SQL(VOID)
|
||||
-------
|
||||
02/06/2023 DJS Adapted from Copy_Backlog_Records_To_SQL
|
||||
\*****************************************************************************/
|
||||
|
||||
#pragma precomp SRP_PreCompiler
|
||||
$Insert APP_INSERTS
|
||||
|
||||
EQU FIVE_MINUTES$ to 0.003472
|
||||
EQU SECONDS_PER_DAY$ to 86400
|
||||
EQU THIRTY_MINUTES$ to 1800
|
||||
|
||||
Declare subroutine Copy_Record_To_SQL, Delete_Record_From_SQL, SRP_TcpClient, Database_Services
|
||||
Declare function GetTickCount, Database_Services, SRP_TcpClient, Datetime, Database_Services, Environment_Services
|
||||
|
||||
Main:
|
||||
|
||||
// This only needs to be called every once in a while (e.g. 5 minutes ~ 0.003472)
|
||||
Run = False$
|
||||
CurrDtm = Datetime()
|
||||
LastRunDtm = Database_Services('ReadDataRow', 'APP_INFO', 'SQL_PENDING_LAST_RUNTIME')
|
||||
If LastRunDtm NE '' then
|
||||
TimeDiff = CurrDtm - LastRunDtm
|
||||
If TimeDiff GT 0.003472 then
|
||||
If TimeDiff GT FIVE_MINUTES$ then
|
||||
Run = True$
|
||||
LastRunDtm = CurrDtm
|
||||
end
|
||||
@ -48,9 +52,9 @@ If Run then
|
||||
|
||||
Read Rec from pTable, Key then
|
||||
TransDtm = Rec<1>
|
||||
ElapSecs = (CurrDtm - TransDtm) * 86400
|
||||
If ElapSecs LT 1800 then
|
||||
// Retry recent pending transactions (1800 seconds = 30 minutes)
|
||||
ElapSecs = (CurrDtm - TransDtm) * SECONDS_PER_DAY$
|
||||
If ElapSecs LT THIRTY_MINUTES$ then
|
||||
// Retry recent pending transactions (i.e., those submitted in the last 30 minutes)
|
||||
Table = Key[1, "*"]
|
||||
Locate Table in NonCriticalTables using @FM setting Dummy then
|
||||
ID = Key[Col2() + 1, Len(Key)]
|
||||
@ -81,9 +85,10 @@ If Run then
|
||||
|
||||
TcpClientHandle = 0
|
||||
ServerIP = Environment_Services('GetApplicationRootIP')
|
||||
ServerPort = Environment_Services('GetScrapeServerPort')
|
||||
Convert '\' to '' in ServerIP
|
||||
|
||||
If SRP_TcpClient(TcpClientHandle, 'CONNECT', ServerIP, '20779') then
|
||||
If SRP_TcpClient(TcpClientHandle, 'CONNECT', ServerIP, ServerPort) then
|
||||
SRP_TcpClient(TcpClientHandle, 'SEND_SES', Command)
|
||||
SRP_TcpClient(TcpClientHandle, 'CLOSE_SES')
|
||||
end
|
||||
@ -103,4 +108,3 @@ end
|
||||
|
||||
Return
|
||||
|
||||
|
||||
|
@ -22,20 +22,29 @@ Compile function Copy_Record_To_SQL(Table, Key, LogError, pKey)
|
||||
09/23/2010 KRF Added logic to set @DICT, @ID, and @RECORD so handlers
|
||||
can use symbolics
|
||||
\*****************************************************************************/
|
||||
$insert Microsoft_Ado_Equates
|
||||
|
||||
If Assigned(LogError) else LogError = 0
|
||||
$Insert APP_INSERTS
|
||||
$Insert MICROSOFT_ADO_EQUATES
|
||||
|
||||
Declare subroutine SRP_Com, Sql_Services
|
||||
Declare function SRP_Com, Environment_Services, Datetime, Sql_Services, Error_Services, Database_Services
|
||||
Ans = ""
|
||||
Declare function SRP_Com, Environment_Services, Datetime, Sql_Services, Error_Services, Database_Services, Unassigned
|
||||
|
||||
Main:
|
||||
|
||||
If Unassigned(LogError) then LogError = False$
|
||||
|
||||
Ans = ""
|
||||
Done = False$
|
||||
// Make sure table is uppercase
|
||||
Convert @LOWER_CASE to @UPPER_CASE in Table
|
||||
|
||||
TablesToSkip = Database_Services('ReadDataRow', 'APP_INFO', 'SQL_TABLES_TO_SKIP')
|
||||
Locate Table in TablesToSkip by "AL" using "," setting ListPos else
|
||||
|
||||
Open 'SQL_PENDING' to pTable then
|
||||
|
||||
If pKey NE '' then Lock pTable, pKey else Done = True$
|
||||
|
||||
If Not(Done) then
|
||||
// The expected name of the handler
|
||||
Handler = "COPY_":Table:"_RECORD_TO_SQL"
|
||||
|
||||
@ -56,9 +65,8 @@ Locate Table in TablesToSkip by "AL" using "," setting ListPos else
|
||||
If Ans EQ '' then
|
||||
If Assigned(pKey) then
|
||||
If pKey NE '' then
|
||||
Open 'SQL_PENDING' to pTable then
|
||||
Delete pTable, pKey else null
|
||||
end
|
||||
Delete pTable, pKey else Null
|
||||
Unlock pTable, pKey else Null
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -68,7 +76,8 @@ Locate Table in TablesToSkip by "AL" using "," setting ListPos else
|
||||
end
|
||||
end
|
||||
end else
|
||||
Ans = 'Unable to open connection to SQL server. SQL connection error: ':SRP_Com(Connection, "ERROR")
|
||||
Ans = 'Unable to open connection to SQL server. SQL connection error: '
|
||||
Ans := SRP_Com(Connection, "ERROR")
|
||||
end
|
||||
SRP_Com(Connection, "CALL", "Close")
|
||||
SRP_Com(Connection, "RELEASE")
|
||||
@ -112,8 +121,8 @@ Locate Table in TablesToSkip by "AL" using "," setting ListPos else
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Return Ans
|
||||
|
||||
|
||||
|
||||
|
@ -18,18 +18,25 @@ Compile function Delete_Record_From_SQL(Table, Key, LogError, pKey)
|
||||
-------
|
||||
09/15/2010 KRF Original Programmer
|
||||
\*****************************************************************************/
|
||||
|
||||
$insert Microsoft_Ado_Equates
|
||||
|
||||
If Assigned(LogError) else LogError = 0
|
||||
$Insert APP_INSERTS
|
||||
$insert MICROSOFT_ADO_EQUATES
|
||||
|
||||
Declare subroutine Sql_Services, SRP_COM
|
||||
Declare function Sql_Services, Error_Services, SRP_COM, Environment_Services
|
||||
Ans = ""
|
||||
Declare function Sql_Services, Error_Services, SRP_COM, Environment_Services, Unassigned
|
||||
|
||||
Main:
|
||||
|
||||
If Unassigned(LogError) else LogError = False$
|
||||
Ans = ""
|
||||
Done = False$
|
||||
// Make sure table is uppercase
|
||||
Convert @LOWER_CASE to @UPPER_CASE in Table
|
||||
|
||||
Open 'SQL_PENDING' to pTable then
|
||||
|
||||
If pKey NE '' then Lock pTable, pKey else Done = True$
|
||||
|
||||
If Not(Done) then
|
||||
// The expected name of the handler
|
||||
Handler = "DELETE_":Table:"_RECORD_FROM_SQL"
|
||||
|
||||
@ -46,9 +53,8 @@ Open "SYSOBJ" to hSysObj then
|
||||
Ans = Function(@Handler(Connection, Key))
|
||||
If Ans EQ '' then
|
||||
If Assigned(pKey) then
|
||||
Open 'SQL_PENDING' to pTable then
|
||||
Delete pTable, pKey else null
|
||||
end
|
||||
Delete pTable, pKey else Null
|
||||
Unlock pTable, pKey else Null
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -78,6 +84,7 @@ end
|
||||
// Always log the result
|
||||
|
||||
If Assigned(pKey) then
|
||||
If (pKey NE '') then
|
||||
Open 'SQL_LOG' to hLog then
|
||||
If Ans EQ '' then
|
||||
Result = 'PROCESSED'
|
||||
@ -93,6 +100,9 @@ If Assigned(pKey) then
|
||||
Write Log to hLog, CurrDate
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Return Ans
|
||||
|
||||
|
@ -565,8 +565,19 @@ Service GetServiceManagerPort()
|
||||
|
||||
end service
|
||||
|
||||
|
||||
Service GetScrapeServerPort()
|
||||
|
||||
FilePath = Drive():'\SRPEngineServerScrape.ini'
|
||||
OSRead IniFile from FilePath then
|
||||
CharIndex = Index(IniFile, 'Port', 1)
|
||||
Line = IniFile[CharIndex, 'F':CRLF$]
|
||||
Response = Trim(Line[-1, 'B='])
|
||||
end
|
||||
|
||||
end service
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Internal GoSubs
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user