Alteração no saveAllToRemote para ser resiliente a falhas. O diff abaixo mostra uma implementação que mesmo que ocorra falha no salvamento de um registro ele tenta novamente com o próximo, somente saindo do loop quando 3 registros em sequencia dão erro de salvamento.
Parametrizar este comportamento.
function TDataIntegradorModuloWeb.saveRecordToRemote(ds: TDataSet; var salvou: boolean): IXMLDomDocument2;
var
http: TIdHTTP;
params: TStringList;
multipartParams: TidMultipartFormDataStream;
xmlContent: string;
doc: IXMLDomDocument2;
idRemoto: integer;
txtUpdate: string;
- _Retry: integer;
stream: TStringStream;
zippedParams: TMemoryStream;
zipper: TAbZipper;
@@ -529,8 +529,8 @@ function TDataIntegradorModuloWeb.saveRecordToRemote(ds: TDataSet; var salvou: b
addTranslatedParams(ds, params, translations);
addDetails(ds, params);
addMoreParams(ds, params);
- sucesso := false;
- while not sucesso do
- _Retry := 1;
- while (_Retry<=3) do
begin
try
if useMultipartParams then
@@ -583,7 +583,6 @@ function TDataIntegradorModuloWeb.saveRecordToRemote(ds: TDataSet; var salvou: b
end;
end;
end;
-
sucesso := true;
CoInitialize(nil);
try
{$IFDEF VER150}
@@ -618,9 +617,11 @@ function TDataIntegradorModuloWeb.saveRecordToRemote(ds: TDataSet; var salvou: b
if Length(TabelasDetalhe) > 0 then
Self.UpdateRecordDetalhe(doc.selectSingleNode(dasherize(nomeSingularSave)), TabelasDetalhe);
end;
-
_Retry := 4;
except
on e: EIdHTTPProtocolException do
begin
-
inc(_Retry);
if e.ErrorCode = 422 then
_Log := Format('Erro ao tentar salvar registro. Classe: %s, Código de erro: %d, Erro: %s.',[ClassName, e.ErrorCode, Self.GetErrorMessage(e.ErrorMessage)])
else if e.ErrorCode = 500 then
@@ -633,7 +634,7 @@ function TDataIntegradorModuloWeb.saveRecordToRemote(ds: TDataSet; var salvou: b
end;
end;
end;
- salvou := _Retry > 3;
finally
FreeAndNil(http);
FreeAndNil(params);
Alteração no saveAllToRemote para ser resiliente a falhas. O diff abaixo mostra uma implementação que mesmo que ocorra falha no salvamento de um registro ele tenta novamente com o próximo, somente saindo do loop quando 3 registros em sequencia dão erro de salvamento.
Parametrizar este comportamento.
function TDataIntegradorModuloWeb.saveRecordToRemote(ds: TDataSet; var salvou: boolean): IXMLDomDocument2;
var
http: TIdHTTP;
params: TStringList;
multipartParams: TidMultipartFormDataStream;
xmlContent: string;
doc: IXMLDomDocument2;
idRemoto: integer;
txtUpdate: string;
stream: TStringStream;
zippedParams: TMemoryStream;
zipper: TAbZipper;
@@ -529,8 +529,8 @@ function TDataIntegradorModuloWeb.saveRecordToRemote(ds: TDataSet; var salvou: b
addTranslatedParams(ds, params, translations);
addDetails(ds, params);
addMoreParams(ds, params);
begin
try
if useMultipartParams then
@@ -583,7 +583,6 @@ function TDataIntegradorModuloWeb.saveRecordToRemote(ds: TDataSet; var salvou: b
end;
end;
end;
@@ -618,9 +617,11 @@ function TDataIntegradorModuloWeb.saveRecordToRemote(ds: TDataSet; var salvou: b
if Length(TabelasDetalhe) > 0 then
Self.UpdateRecordDetalhe(doc.selectSingleNode(dasherize(nomeSingularSave)), TabelasDetalhe);
end;
@@ -633,7 +634,7 @@ function TDataIntegradorModuloWeb.saveRecordToRemote(ds: TDataSet; var salvou: b
end;
end;
end;
finally
FreeAndNil(http);
FreeAndNil(params);