Skip to content

Instantly share code, notes, and snippets.

@alieniasty
Last active February 17, 2021 10:43
Show Gist options
  • Save alieniasty/f0b446eede18f534d93d98ff744a8887 to your computer and use it in GitHub Desktop.
Save alieniasty/f0b446eede18f534d93d98ff744a8887 to your computer and use it in GitHub Desktop.
Polly retry with Circuit Breaker
_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