Po hlavnich upravach sdileni sponeni a uvolnovani connection poolu
This commit is contained in:
@ -55,7 +55,7 @@
|
||||
var lSQL, errMsg, url, outData, fName, loopCasTyp: string;
|
||||
lLoop, idDigiFile, cnt, idx: Integer;
|
||||
lLoopMax, koefProCas: integer;
|
||||
logRunCnt: integer;
|
||||
logRunCnt, intTemp: integer;
|
||||
Msg: TMsg;
|
||||
firstRun, inProg, inDL: boolean;
|
||||
lQry: TFDQuery;
|
||||
@ -95,137 +95,140 @@
|
||||
|
||||
attrIdx:= attribs.IndexOf('zapisObjMatExpPrIntMins');
|
||||
if (attrIdx>-1) then
|
||||
if (attribs.Get(attrIdx).NodeValue<>null) then
|
||||
lLoopMax:= attribs.Get(attrIdx).NodeValue;
|
||||
if TryStrToInt(VarToStr(attribs.Get(attrIdx).NodeValue), intTemp) then
|
||||
lLoopMax:= intTemp;
|
||||
end; // n1 = config
|
||||
end; // specCfgXML.DocumentElement<>nil
|
||||
end; // not specCfgXML.IsEmptyDoc
|
||||
end; // FileExists(cfgFile)
|
||||
except
|
||||
on E: Exception do
|
||||
datMod.LogInfo (Quick.Logger.etError, 'Chyba cteni konfigu THeoRTNZapisObjMatThread: ' + E.Message);
|
||||
end;
|
||||
finally
|
||||
begin
|
||||
if (specCfgXML<>nil) then
|
||||
specCfgXML:= nil;
|
||||
specCfgXML := nil;
|
||||
CoUninitialize;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
datMod.LogInfo (Quick.Logger.etInfo, 'Zapis Objednavek materialu do ExpPr - interval: ' + lLoopMax.ToString + ' min.');
|
||||
lLoopMax:= lLoopMax * 60; // minuty na vteriny
|
||||
lLoopMax := lLoopMax * 60; // minuty na vteriny
|
||||
|
||||
|
||||
firstRun:= true;
|
||||
inProg:= false;
|
||||
FRunning:= true;
|
||||
firstRun := true;
|
||||
inProg := false;
|
||||
FRunning := true;
|
||||
|
||||
if (1=1) then // pro rychle vypnuti
|
||||
begin
|
||||
FTimer:= CreateWaitableTimer (nil, true, 'RTNZapisObjMatExpPrWaitableTimer');
|
||||
liDueTime.QuadPart:= -1*_Second;
|
||||
FTimer := CreateWaitableTimer (nil, true, 'RTNZapisObjMatExpPrWaitableTimer');
|
||||
liDueTime.QuadPart := -1*_Second;
|
||||
|
||||
|
||||
sqlConnX:= TFDConnection.Create (nil);
|
||||
sqlConnX.Params.SetStrings (datMod.sqlConnParams);
|
||||
lSQL:= 'DECLARE @errMsg NVARCHAR(500)=N''''' + CRLF +'IF OBJECT_ID(N''dbo.ep_Vyroba_GenObjednavkuMatDoVyrobyNew'', N''P'') IS NOT NULL' + CRLF
|
||||
+ ' EXEC dbo.ep_Vyroba_GenObjednavkuMatDoVyrobyNew @errMsg OUT' + CRLF + 'SELECT @errMsg AS ErrMsg';
|
||||
lQry:= TFDQuery.Create(nil);
|
||||
|
||||
try
|
||||
lQry.Connection:= sqlConnX;
|
||||
|
||||
while not(Terminated) or not(FRunning) do
|
||||
begin
|
||||
if (HDCDZApiService<>nil) then
|
||||
if (HDCDZApiService.Terminated) then
|
||||
begin
|
||||
Terminate;
|
||||
FRunning:= false;
|
||||
end;
|
||||
|
||||
PeekMessage (&Msg, 0, 0, 0, PM_NOREMOVE); { Create message queue }
|
||||
|
||||
if (lLoop=lLoopMax) or (firstRun) then // pri startu a pak kazdou minutu
|
||||
while not(Terminated) and FRunning do
|
||||
begin
|
||||
if (HDCDZApiService<>nil) then
|
||||
if (HDCDZApiService.Terminated) then
|
||||
begin
|
||||
idDigiFile:= 0;
|
||||
firstRun:= false;
|
||||
Terminate;
|
||||
FRunning:= false;
|
||||
end;
|
||||
|
||||
if (logRunCnt<4) then
|
||||
datMod.LogInfo (Quick.Logger.etInfo, 'Spoustim zapis Objednavky materialu do ExpPr c.' + logRunCnt.toString + '...');
|
||||
if (logRunCnt=4) then
|
||||
datMod.LogInfo (Quick.Logger.etInfo, 'Spoustim zapis Objednavky - bezi, ale dal neloguju');
|
||||
PeekMessage (&Msg, 0, 0, 0, PM_NOREMOVE); { Create message queue }
|
||||
|
||||
try
|
||||
if not(inProg) then // nebezi uz ?
|
||||
begin
|
||||
if (lLoop=lLoopMax) or (firstRun) then // pri startu a pak kazdou minutu
|
||||
begin
|
||||
|
||||
if (1=1) then // pro rychle vypnuti
|
||||
sqlConnX := TFDConnection.Create (nil);
|
||||
try
|
||||
sqlConnX.Params.SetStrings (datMod.sqlConnParams);
|
||||
lQry := TFDQuery.Create(nil);
|
||||
try
|
||||
lQry.Connection := sqlConnX;
|
||||
|
||||
idDigiFile:= 0;
|
||||
firstRun:= false;
|
||||
|
||||
if (logRunCnt<4) then
|
||||
datMod.LogInfo (Quick.Logger.etInfo, 'Spoustim zapis Objednavky materialu do ExpPr c.' + logRunCnt.toString + '...');
|
||||
if (logRunCnt=4) then
|
||||
datMod.LogInfo (Quick.Logger.etInfo, 'Spoustim zapis Objednavky - bezi, ale dal neloguju');
|
||||
|
||||
try
|
||||
if not(inProg) then // nebezi uz ?
|
||||
begin
|
||||
|
||||
if (1=1) then // pro rychle vypnuti
|
||||
begin
|
||||
sqlConnX.Open;
|
||||
if (sqlConnX.Connected) then
|
||||
begin
|
||||
inProg:= true;
|
||||
|
||||
lSQL:= 'DECLARE @errMsg NVARCHAR(500)=N''''' + CRLF +'IF OBJECT_ID(N''dbo.ep_Vyroba_GenObjednavkuMatDoVyrobyNew'', N''P'') IS NOT NULL' + CRLF
|
||||
+ ' EXEC dbo.ep_Vyroba_GenObjednavkuMatDoVyrobyNew @errMsg OUT' + CRLF + 'SELECT @errMsg AS ErrMsg';
|
||||
|
||||
lQry.Open(lSQL);
|
||||
if (lQry.RecordCount>0) then
|
||||
begin
|
||||
lQry.First;
|
||||
errMsg:= lQry.FieldByName('ErrMsg').AsString;
|
||||
if (errMsg<>'') then
|
||||
begin
|
||||
datMod.LogInfo (Quick.Logger.etInfo, 'Zapis Objednavky materialu do ExpPr - chyba: ' + errMsg);
|
||||
{$IFDEF DEBUG}
|
||||
WriteLn('Zapis Objednavky materialu do ExpPr - chyba: ' + errMsg);
|
||||
{$ENDIF}
|
||||
end;
|
||||
end;
|
||||
|
||||
inProg:= false;
|
||||
end; // sql Connected
|
||||
end; // 1=1
|
||||
end;
|
||||
|
||||
except on E:Exception do
|
||||
begin
|
||||
sqlConnX.Open;
|
||||
if (sqlConnX.Connected) then
|
||||
inProg:= false;
|
||||
errMsg:= E.Message; // datMod.sqlQry11.FieldByName('ErrMsg').AsString;
|
||||
if (mamTabPrijataData) then
|
||||
begin
|
||||
inProg:= true;
|
||||
lQry.Open(lSQL);
|
||||
if (lQry.RecordCount>0) then
|
||||
begin
|
||||
lQry.First;
|
||||
errMsg:= lQry.FieldByName('ErrMsg').AsString;
|
||||
if (errMsg<>'') then
|
||||
begin
|
||||
datMod.LogInfo (Quick.Logger.etInfo, 'Zapis Objednavky materialu do ExpPr - chyba: ' + errMsg);
|
||||
{$IFDEF DEBUG}
|
||||
WriteLn('Zapis Objednavky materialu do ExpPr - chyba: ' + errMsg);
|
||||
{$ENDIF}
|
||||
end;
|
||||
end;
|
||||
lQry.Close;
|
||||
inProg:= false;
|
||||
end; // sql Connected
|
||||
datMod.LogInfo (Quick.Logger.etError, 'Zapis Objednavky materialu do ExpPr - chyba: ' + errMsg);
|
||||
{$IFDEF DEBUG}
|
||||
WriteLn('Zapis Objednavky materialu do ExpPr - chyba: ' + errMsg);
|
||||
{$ENDIF}
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
lQry.Free;
|
||||
end;
|
||||
|
||||
except on E:Exception do
|
||||
begin
|
||||
inProg:= false;
|
||||
errMsg:= E.Message; // datMod.sqlQry11.FieldByName('ErrMsg').AsString;
|
||||
if (mamTabPrijataData) then
|
||||
begin
|
||||
datMod.LogInfo (Quick.Logger.etError, 'Zapis Objednavky materialu do ExpPr - chyba: ' + errMsg);
|
||||
{$IFDEF DEBUG}
|
||||
WriteLn('Zapis Objednavky materialu do ExpPr - chyba: ' + errMsg);
|
||||
{$ENDIF}
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
lLoop:= 0;
|
||||
if (logRunCnt<5) then
|
||||
Inc (logRunCnt);
|
||||
finally
|
||||
sqlConnX.Free;
|
||||
end;
|
||||
Inc (lLoop);
|
||||
|
||||
if (FTimer<>0) then
|
||||
SetWaitableTimer (FTimer, TLargeInteger(liDueTime), 0, nil, nil, false);
|
||||
repeat
|
||||
lBusy:= MsgWaitForMultipleObjects (1, FTimer, false, INFINITE, QS_ALLINPUT);
|
||||
until lBusy = WAIT_OBJECT_0;
|
||||
lLoop:= 0;
|
||||
if (logRunCnt<5) then
|
||||
Inc (logRunCnt);
|
||||
end; // if lLoop=lLoopMax...
|
||||
|
||||
Inc (lLoop);
|
||||
|
||||
|
||||
if (FTimer<>0) then
|
||||
SetWaitableTimer (FTimer, TLargeInteger(liDueTime), 0, nil, nil, false);
|
||||
repeat
|
||||
lBusy:= MsgWaitForMultipleObjects (1, FTimer, false, INFINITE, QS_ALLINPUT);
|
||||
until lBusy = WAIT_OBJECT_0;
|
||||
// Sleep (998);
|
||||
|
||||
end;
|
||||
finally
|
||||
end;
|
||||
end; // while not(Terminated) and FRunning
|
||||
|
||||
if (lQry<>nil) then
|
||||
begin
|
||||
lQry.Close;
|
||||
FreeAndNil (lQry);
|
||||
end;
|
||||
if (sqlConnX<>nil) then
|
||||
begin
|
||||
sqlConnX.Close;
|
||||
FreeAndNil (sqlConnX);
|
||||
end;
|
||||
if (FTimer<>0) then
|
||||
CloseHandle (FTimer);
|
||||
|
||||
end; // 1=1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user