Last active
February 17, 2021 10:43
-
-
Save alieniasty/f0b446eede18f534d93d98ff744a8887 to your computer and use it in GitHub Desktop.
Polly retry with Circuit Breaker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_retryPolicy = Policy | |
.Handle<CosmosException>() | |
.WaitAndRetryAsync(2, i => | |
{ | |
var timeToWait = TimeSpan.FromSeconds(1); | |
return timeToWait; | |
}); | |
_concurrencyExceptionPolicy = Policy | |
.Handle<CosmosException>() | |
.CircuitBreakerAsync( | |
2, | |
TimeSpan.FromSeconds(1), | |
(exception, span) => throw new ConcurrencyException("User data has changed while attempting to add scope. Please retry."), //throw another ex after breaking the circuit | |
() => {}, | |
() => {}); | |
var updateCorePropertiesPolicy = _retryPolicy.WrapAsync(_concurrencyExceptionPolicy); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment