Skip to content

Commit 80dc4a2

Browse files
committed
Allow configuration of retry count
1 parent 7f20b44 commit 80dc4a2

5 files changed

Lines changed: 17 additions & 3 deletions

File tree

RELEASE_NOTES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
subject to change
1111
* New: Now possible to configure retry delay for MSSQL error `40501` (server
1212
too busy) using `IMsSqlConfiguration.SetServerBusyRetryDelay(RetryDelay)`
13+
* New: Now possible to configure the retry count of transient exceptions for
14+
MSSQL and SQLite using the `ISqlConfiguration.SetTransientRetryCount(int)`
1315
* Fixed: Added MSSQL error codes `10928`, `10929`, `18401` and `40540` as well
1416
as a few native `Win32Exception` exceptions to the list treated as transient
1517
errors, i.e., EventFlow will automatically retry if the server returns one

Source/EventFlow.MsSql/RetryStrategies/MsSqlErrorRetryStrategy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public virtual Retry ShouldThisBeRetried(
5252
// List of possible errors inspired by Azure SqlDatabaseTransientErrorDetectionStrategy
5353

5454
var sqlException = exception as SqlException;
55-
if (sqlException == null || currentRetryCount > 2)
55+
if (sqlException == null || currentRetryCount > _msSqlConfiguration.TransientRetryCount)
5656
{
5757
return Retry.No;
5858
}

Source/EventFlow.SQLite/RetryStrategies/SQLiteErrorRetryStrategy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public SQLiteErrorRetryStrategy(
4141
public Retry ShouldThisBeRetried(Exception exception, TimeSpan totalExecutionTime, int currentRetryCount)
4242
{
4343
var sqLiteException = exception as SQLiteException;
44-
if (sqLiteException == null || currentRetryCount > 2)
44+
if (sqLiteException == null || currentRetryCount > _configuration.TransientRetryCount)
4545
{
4646
return Retry.No;
4747
}

Source/EventFlow.Sql/Connections/ISqlConfiguration.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ namespace EventFlow.Sql.Connections
2828
public interface ISqlConfiguration<out T>
2929
where T : ISqlConfiguration<T>
3030
{
31-
RetryDelay TransientRetryDelay { get; }
3231
string ConnectionString { get; }
32+
RetryDelay TransientRetryDelay { get; }
33+
int TransientRetryCount { get; }
3334

3435
T SetTransientRetryDelay(RetryDelay retryDelay);
36+
T SetTransientRetryCount(int retryCount);
3537
}
3638
}

Source/EventFlow.Sql/Connections/SqlConfiguration.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public abstract class SqlConfiguration<T> : ISqlConfiguration<T>
3535
TimeSpan.FromMilliseconds(50),
3636
TimeSpan.FromMilliseconds(100));
3737

38+
public int TransientRetryCount { get; private set; } = 2;
39+
3840
public T SetConnectionString(string connectionString)
3941
{
4042
ConnectionString = connectionString;
@@ -50,5 +52,13 @@ public T SetTransientRetryDelay(RetryDelay retryDelay)
5052
// Are there alternatives to this double cast?
5153
return (T)(object)this;
5254
}
55+
56+
public T SetTransientRetryCount(int retryCount)
57+
{
58+
TransientRetryCount = retryCount;
59+
60+
// Are there alternatives to this double cast?
61+
return (T)(object)this;
62+
}
5363
}
5464
}

0 commit comments

Comments
 (0)