Skip to content

Commit

Permalink
Add exponential error backoff
Browse files Browse the repository at this point in the history
  • Loading branch information
jaensen committed May 17, 2024
1 parent 05310c4 commit 7eb817b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions Circles.Index/StateMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,16 @@ public async Task HandleEvent(IEvent e)
switch (e)
{
case EnterState:
await TransitionTo(Errors.Count >= 3
? State.End
: State.Initial);
if (Errors.Count >= 3)
{
// If we have tried 3 times, give up
await TransitionTo(State.End);
return;
}

// Otherwise, wait for a bit before retrying
await Task.Delay(Errors.Count * Errors.Count * 1000, cancellationToken);
await TransitionTo(State.Initial);
return;
case LeaveState:
return;
Expand Down

0 comments on commit 7eb817b

Please sign in to comment.