Skip to content

Commit

Permalink
fix: correctly stack MaxFailedAttempts in ErrorPolicyChain
Browse files Browse the repository at this point in the history
  • Loading branch information
BEagle1984 committed Mar 16, 2023
1 parent ce93478 commit 4b5b6b7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup Label="Package information">
<BaseVersionSuffix></BaseVersionSuffix>
<BaseVersion>4.1.1$(BaseVersionSuffix)</BaseVersion>
<BaseVersion>4.1.2$(BaseVersionSuffix)</BaseVersion>
<DatabasePackagesRevision>1</DatabasePackagesRevision>
<DatabasePackagesVersionSuffix>$(BaseVersionSuffix)</DatabasePackagesVersionSuffix>
</PropertyGroup>
Expand Down
7 changes: 6 additions & 1 deletion docs/releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ uid: releases

# Releases

## [4.1.2](https://github.com/BEagle1984/silverback/releases/tag/v4.1.2)

### Fixes

* Fix chained error policies attempts counter

## [4.1.1](https://github.com/BEagle1984/silverback/releases/tag/v4.1.1)

### Fixes

* Fix bug in outbox producer writing to the wrong endpoint [[#165](https://github.com/BEagle1984/silverback/issues/165)]


## [4.1.0](https://github.com/BEagle1984/silverback/releases/tag/v4.1.0)

### What's new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace Silverback.Messaging.Inbound.ErrorHandling
/// </summary>
public class ErrorPolicyChain : IErrorPolicy
{
private bool _failedAttemptsStacked;

/// <summary>
/// Initializes a new instance of the <see cref="ErrorPolicyChain" /> class.
/// </summary>
Expand Down Expand Up @@ -50,19 +52,23 @@ public IErrorPolicyImplementation Build(IServiceProvider serviceProvider) =>
.Cast<ErrorPolicyImplementation>(),
serviceProvider.GetRequiredService<IInboundLogger<ErrorPolicyChainImplementation>>());

private static IReadOnlyCollection<ErrorPolicyBase> StackMaxFailedAttempts(
IReadOnlyCollection<ErrorPolicyBase> policies)
private IReadOnlyCollection<ErrorPolicyBase> StackMaxFailedAttempts(IReadOnlyCollection<ErrorPolicyBase> policies)
{
if (_failedAttemptsStacked)
return policies;

var totalAttempts = 0;
foreach (var policy in policies)
{
if (policy.MaxFailedAttemptsCount == null || policy.MaxFailedAttemptsCount <= 0)
if (policy.MaxFailedAttemptsCount is null or <= 0)
continue;

totalAttempts += policy.MaxFailedAttemptsCount.Value;
policy.MaxFailedAttemptsCount = totalAttempts;
}

_failedAttemptsStacked = true;

return policies;
}

Expand Down

0 comments on commit 4b5b6b7

Please sign in to comment.