Skip to content

Commit

Permalink
Merge branch 'dev' into akkadotnet#7358-Fix-async-circuit-breaker
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/core/Akka.Persistence/Snapshot/SnapshotStore.cs
  • Loading branch information
Arkatufus committed Oct 23, 2024
2 parents d285573 + de98c10 commit a1564e0
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/core/Akka.Persistence/Snapshot/SnapshotStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading;
using System.Threading.Tasks;
using Akka.Actor;
using Akka.Event;
using Akka.Pattern;

namespace Akka.Persistence.Snapshot
Expand All @@ -21,6 +22,7 @@ public abstract class SnapshotStore : ActorBase
private readonly TaskContinuationOptions _continuationOptions = TaskContinuationOptions.ExecuteSynchronously;
private readonly bool _publish;
private readonly CircuitBreaker _breaker;
private readonly ILoggingAdapter _log;

/// <summary>
/// Initializes a new instance of the <see cref="SnapshotStore"/> class.
Expand All @@ -43,6 +45,8 @@ protected SnapshotStore()
config.GetInt("circuit-breaker.max-failures", 10),
config.GetTimeSpan("circuit-breaker.call-timeout", TimeSpan.FromSeconds(10)),
config.GetTimeSpan("circuit-breaker.reset-timeout", TimeSpan.FromSeconds(30)));

_log = Context.GetLogger();
}

/// <inheritdoc/>
Expand Down Expand Up @@ -104,7 +108,16 @@ private bool ReceiveSnapshotStore(object message)
try
{
ReceivePluginInternal(message);
_breaker.WithCircuitBreaker(ct => DeleteAsync(saveSnapshotFailure.Metadata, ct));
_breaker.WithCircuitBreaker(ct => DeleteAsync(saveSnapshotFailure.Metadata, ct))
.ContinueWith(t =>
{
if(t.IsFaulted)
_log.Error(t.Exception, "DeleteAsync operation after SaveSnapshot failure failed.");
else if(t.IsCanceled)
_log.Error(t.Exception, t.Exception is not null
? "DeleteAsync operation after SaveSnapshot failure canceled."
: "DeleteAsync operation after SaveSnapshot failure canceled, possibly due to timing out.");
}, TaskContinuationOptions.ExecuteSynchronously);
}
finally
{
Expand Down

0 comments on commit a1564e0

Please sign in to comment.