Skip to content

Commit 12973d5

Browse files
committed
Initial import
1 parent df58512 commit 12973d5

7 files changed

+808
-0
lines changed

Diff for: README.md

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Retry Policy
2+
Retry Policy is a small class which helps to build robust code. I allows you as developer to retry or wait and retry function that have failed before. This is done in fluent manner.
3+
4+
# Install / Usage
5+
6+
Just include the "source\Bott.RetryPolicy.pas" into your project. Then call `TRetryPolicyFactory.GetInstance()` to get an instance of `IRetryPolicy`.
7+
8+
## Retry 3 times (4 tries in total when they fail - initial call and 3 tries)
9+
``` delphi
10+
TRetryPolicyFactory.GetInstance()
11+
.Retry(3)
12+
.Execute(
13+
procedure()
14+
begin
15+
// your code here
16+
end
17+
)
18+
```
19+
20+
This code retries three times to execute `your code`. If one of the 4 calls does not raise an exception, the methode `execute` returns `true`. if not `false` will returned.
21+
22+
## Wait 1 second between each retry and try it 3 times
23+
``` delphi
24+
TRetryPolicyFactory.GetInstance()
25+
.WaitAndRetry(1000, 2)
26+
.Execute(
27+
procedure()
28+
begin
29+
// your code here
30+
end
31+
)
32+
```
33+
34+
## Chain the trys
35+
First call to `your code` will be instant. If this fails wait 1 second and retry. If second call also raises an exception, wait 3 second before the last try.
36+
``` delphi
37+
TRetryPolicyFactory.GetInstance()
38+
.WaitAndRetry(1000)
39+
.WaitAndRetry(3000)
40+
.Execute(
41+
procedure()
42+
begin
43+
// your code here
44+
end
45+
)
46+
```
47+
## Use callback to log and/or handle exceptions
48+
49+
``` delphi
50+
TRetryPolicyFactory.GetInstance()
51+
.onException(
52+
function(e: Exception): boolean
53+
begin
54+
// return true when the exception is handled.
55+
// return false when the exception should re raise.
56+
result:=true;
57+
end
58+
)
59+
.Execute(
60+
procedure()
61+
begin
62+
// your code here
63+
end
64+
);
65+
```
66+
67+
## Use callback to decide if retries should done
68+
69+
``` delphi
70+
TRetryPolicyFactory.GetInstance()
71+
.onRetry( function(retry, maxRetries: cardinal; lastException: Exception): boolean
72+
begin
73+
// do in total call `your code` three times.
74+
result:=retry<3;
75+
end
76+
)
77+
.Execute(
78+
procedure()
79+
begin
80+
// your code here
81+
end
82+
)
83+
```
84+
85+
# License
86+
87+
Licensed under the terms of the [New BSD License](http://opensource.org/licenses/BSD-3-Clause)
88+
89+
## The 3-Clause BSD License aka "New BSD License" or "Modified BSD License"
90+
91+
Copyright (c) 2020 Bernd Ott aka codingBOTT
92+
All rights reserved.
93+
94+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
95+
96+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
97+
98+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
99+
100+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
101+
102+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
103+
104+
# discussion board
105+
When you want to discuss this class, join the community here : [delphipraxis.net](https://en.delphipraxis.net/)

Diff for: RetryPolicy.dpr

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
program RetryPolicy;
2+
{
3+
4+
Delphi DUnit-Testprojekt
5+
-------------------------
6+
Dieses Projekt enthält das DUnit-Test-Framework und die GUI/Konsolen-Test-Runner.
7+
Fügen Sie den Bedingungen in den Projektoptionen "CONSOLE_TESTRUNNER" hinzu,
8+
um den Konsolen-Test-Runner zu verwenden. Ansonsten wird standardmäßig der
9+
GUI-Test-Runner verwendet.
10+
11+
}
12+
13+
{$IFDEF CONSOLE_TESTRUNNER}
14+
{$APPTYPE CONSOLE}
15+
{$ENDIF}
16+
17+
uses
18+
DUnitTestRunner,
19+
Bott.RetryPolicy in 'source\Bott.RetryPolicy.pas',
20+
Bott.RetryPolicy.Tests in 'tests\Bott.RetryPolicy.Tests.pas';
21+
22+
{$R *.RES}
23+
24+
begin
25+
ReportMemoryLeaksOnShutdown:=true;
26+
DUnitTestRunner.RunRegisteredTests;
27+
end.
28+

Diff for: RetryPolicy.dproj

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<PropertyGroup>
3+
<ProjectGuid>{9C3FFFCF-9C0A-44BC-9D5E-C7D14BEF0FCF}</ProjectGuid>
4+
<MainSource>RetryPolicy.dpr</MainSource>
5+
<Base>True</Base>
6+
<Config Condition="'$(Config)'==''">Debug</Config>
7+
<TargetedPlatforms>1</TargetedPlatforms>
8+
<AppType>Console</AppType>
9+
<FrameworkType>None</FrameworkType>
10+
<ProjectVersion>15.3</ProjectVersion>
11+
<Platform Condition="'$(Platform)'==''">Win32</Platform>
12+
</PropertyGroup>
13+
<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
14+
<Base>true</Base>
15+
</PropertyGroup>
16+
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Base)'=='true') or '$(Base_Win32)'!=''">
17+
<Base_Win32>true</Base_Win32>
18+
<CfgParent>Base</CfgParent>
19+
<Base>true</Base>
20+
</PropertyGroup>
21+
<PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_1)'!=''">
22+
<Cfg_1>true</Cfg_1>
23+
<CfgParent>Base</CfgParent>
24+
<Base>true</Base>
25+
</PropertyGroup>
26+
<PropertyGroup Condition="'$(Config)'=='Debug' or '$(Cfg_2)'!=''">
27+
<Cfg_2>true</Cfg_2>
28+
<CfgParent>Base</CfgParent>
29+
<Base>true</Base>
30+
</PropertyGroup>
31+
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Cfg_2)'=='true') or '$(Cfg_2_Win32)'!=''">
32+
<Cfg_2_Win32>true</Cfg_2_Win32>
33+
<CfgParent>Cfg_2</CfgParent>
34+
<Cfg_2>true</Cfg_2>
35+
<Base>true</Base>
36+
</PropertyGroup>
37+
<PropertyGroup Condition="'$(Base)'!=''">
38+
<VerInfo_Locale>1031</VerInfo_Locale>
39+
<DCC_S>false</DCC_S>
40+
<DCC_K>false</DCC_K>
41+
<DCC_ImageBase>00400000</DCC_ImageBase>
42+
<DCC_Namespace>System;Xml;Data;Datasnap;Web;Soap;$(DCC_Namespace)</DCC_Namespace>
43+
<Manifest_File>$(BDS)\bin\default_app.manifest</Manifest_File>
44+
<DCC_ExeOutput>.\bin</DCC_ExeOutput>
45+
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=;CFBundleName=;CFBundleDisplayName=;UIDeviceFamily=;CFBundleIdentifier=;CFBundleVersion=;CFBundlePackageType=;CFBundleSignature=;CFBundleAllowMixedLocalizations=;UISupportedInterfaceOrientations=;CFBundleExecutable=;CFBundleResourceSpecification=;LSRequiresIPhoneOS=;CFBundleInfoDictionaryVersion=;CFBundleDevelopmentRegion=;package=;label=;versionCode=;versionName=;persistent=;restoreAnyVersion=;installLocation=;largeHeap=;theme=</VerInfo_Keys>
46+
<DCC_F>false</DCC_F>
47+
<DCC_E>false</DCC_E>
48+
<DCC_N>false</DCC_N>
49+
<DCC_DcuOutput>.\obj</DCC_DcuOutput>
50+
</PropertyGroup>
51+
<PropertyGroup Condition="'$(Base_Win32)'!=''">
52+
<DCC_Namespace>Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)</DCC_Namespace>
53+
<VerInfo_Locale>1033</VerInfo_Locale>
54+
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
55+
</PropertyGroup>
56+
<PropertyGroup Condition="'$(Cfg_1)'!=''">
57+
<DCC_SymbolReferenceInfo>0</DCC_SymbolReferenceInfo>
58+
<DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
59+
<DCC_DebugInformation>0</DCC_DebugInformation>
60+
<DCC_Define>RELEASE;$(DCC_Define)</DCC_Define>
61+
</PropertyGroup>
62+
<PropertyGroup Condition="'$(Cfg_2)'!=''">
63+
<DCC_Optimize>false</DCC_Optimize>
64+
<DCC_GenerateStackFrames>true</DCC_GenerateStackFrames>
65+
<DCC_Define>DEBUG;$(DCC_Define)</DCC_Define>
66+
</PropertyGroup>
67+
<PropertyGroup Condition="'$(Cfg_2_Win32)'!=''">
68+
<Manifest_File>None</Manifest_File>
69+
<VerInfo_Locale>1033</VerInfo_Locale>
70+
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
71+
</PropertyGroup>
72+
<ItemGroup>
73+
<DelphiCompile Include="$(MainSource)">
74+
<MainSource>MainSource</MainSource>
75+
</DelphiCompile>
76+
<DCCReference Include="source\Bott.RetryPolicy.pas"/>
77+
<DCCReference Include="tests\Bott.RetryPolicy.Tests.pas"/>
78+
<None Include="README.md"/>
79+
<BuildConfiguration Include="Debug">
80+
<Key>Cfg_2</Key>
81+
<CfgParent>Base</CfgParent>
82+
</BuildConfiguration>
83+
<BuildConfiguration Include="Base">
84+
<Key>Base</Key>
85+
</BuildConfiguration>
86+
<BuildConfiguration Include="Release">
87+
<Key>Cfg_1</Key>
88+
<CfgParent>Base</CfgParent>
89+
</BuildConfiguration>
90+
</ItemGroup>
91+
<ProjectExtensions>
92+
<Borland.Personality>Delphi.Personality.12</Borland.Personality>
93+
<Borland.ProjectType/>
94+
<BorlandProject>
95+
<Delphi.Personality>
96+
<Source>
97+
<Source Name="MainSource">RetryPolicy.dpr</Source>
98+
</Source>
99+
<VersionInfo>
100+
<VersionInfo Name="IncludeVerInfo">False</VersionInfo>
101+
<VersionInfo Name="AutoIncBuild">False</VersionInfo>
102+
<VersionInfo Name="MajorVer">1</VersionInfo>
103+
<VersionInfo Name="MinorVer">0</VersionInfo>
104+
<VersionInfo Name="Release">0</VersionInfo>
105+
<VersionInfo Name="Build">0</VersionInfo>
106+
<VersionInfo Name="Debug">False</VersionInfo>
107+
<VersionInfo Name="PreRelease">False</VersionInfo>
108+
<VersionInfo Name="Special">False</VersionInfo>
109+
<VersionInfo Name="Private">False</VersionInfo>
110+
<VersionInfo Name="DLL">False</VersionInfo>
111+
<VersionInfo Name="Locale">1031</VersionInfo>
112+
<VersionInfo Name="CodePage">1252</VersionInfo>
113+
</VersionInfo>
114+
<VersionInfoKeys>
115+
<VersionInfoKeys Name="CompanyName"/>
116+
<VersionInfoKeys Name="FileDescription"/>
117+
<VersionInfoKeys Name="FileVersion">1.0.0.0</VersionInfoKeys>
118+
<VersionInfoKeys Name="InternalName"/>
119+
<VersionInfoKeys Name="LegalCopyright"/>
120+
<VersionInfoKeys Name="LegalTrademarks"/>
121+
<VersionInfoKeys Name="OriginalFilename"/>
122+
<VersionInfoKeys Name="ProductName"/>
123+
<VersionInfoKeys Name="ProductVersion">1.0.0.0</VersionInfoKeys>
124+
<VersionInfoKeys Name="Comments"/>
125+
<VersionInfoKeys Name="CFBundleName"/>
126+
<VersionInfoKeys Name="CFBundleDisplayName"/>
127+
<VersionInfoKeys Name="UIDeviceFamily"/>
128+
<VersionInfoKeys Name="CFBundleIdentifier"/>
129+
<VersionInfoKeys Name="CFBundleVersion"/>
130+
<VersionInfoKeys Name="CFBundlePackageType"/>
131+
<VersionInfoKeys Name="CFBundleSignature"/>
132+
<VersionInfoKeys Name="CFBundleAllowMixedLocalizations"/>
133+
<VersionInfoKeys Name="UISupportedInterfaceOrientations"/>
134+
<VersionInfoKeys Name="CFBundleExecutable"/>
135+
<VersionInfoKeys Name="CFBundleResourceSpecification"/>
136+
<VersionInfoKeys Name="LSRequiresIPhoneOS"/>
137+
<VersionInfoKeys Name="CFBundleInfoDictionaryVersion"/>
138+
<VersionInfoKeys Name="CFBundleDevelopmentRegion"/>
139+
<VersionInfoKeys Name="package"/>
140+
<VersionInfoKeys Name="label"/>
141+
<VersionInfoKeys Name="versionCode"/>
142+
<VersionInfoKeys Name="versionName"/>
143+
<VersionInfoKeys Name="persistent"/>
144+
<VersionInfoKeys Name="restoreAnyVersion"/>
145+
<VersionInfoKeys Name="installLocation"/>
146+
<VersionInfoKeys Name="largeHeap"/>
147+
<VersionInfoKeys Name="theme"/>
148+
</VersionInfoKeys>
149+
<Excluded_Packages>
150+
<Excluded_Packages Name="$(BDSBIN)\dcloffice2k190.bpl">Microsoft Office 2000 Beispiele für gekapselte Komponenten für Automatisierungsserver</Excluded_Packages>
151+
<Excluded_Packages Name="$(BDSBIN)\dclofficexp190.bpl">Microsoft Office XP Beispiele für gekapselte Komponenten für Automation Server</Excluded_Packages>
152+
</Excluded_Packages>
153+
</Delphi.Personality>
154+
<Platforms>
155+
<Platform value="Win32">True</Platform>
156+
<Platform value="Win64">False</Platform>
157+
</Platforms>
158+
</BorlandProject>
159+
<ProjectFileVersion>12</ProjectFileVersion>
160+
</ProjectExtensions>
161+
<Import Project="$(BDS)\Bin\CodeGear.Delphi.Targets" Condition="Exists('$(BDS)\Bin\CodeGear.Delphi.Targets')"/>
162+
<Import Project="$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj" Condition="Exists('$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj')"/>
163+
</Project>

Diff for: RetryPolicy.res

96 Bytes
Binary file not shown.

Diff for: license.txt

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
The 3-Clause BSD License aka "New BSD License" or "Modified BSD License"
2+
3+
Copyright (c) 2020 Bernd Ott
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7+
8+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9+
10+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
11+
12+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
13+
14+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

0 commit comments

Comments
 (0)