Created
July 27, 2018 15:03
-
-
Save marraia/304d2baf4116a4166d1fecb6cc43e094 to your computer and use it in GitHub Desktop.
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
private CircuitBreakerPolicy CircuitBreakerPolicy() | |
{ | |
var circuitBreaker= Policy<ApiResponse> | |
.Handle<HttpRequestException>() | |
.CircuitBreakerAsync( | |
durationOfBreak: TimeSpan.FromSeconds(30), | |
handledEventsAllowedBeforeBreaking: 1, | |
onBreak: async (result, timeSpan) => | |
{ | |
await CircuitOpen(result,timeSpan); | |
}, | |
onReset: async () => | |
{ | |
var msg ="CLOSING CIRCUIT! (CIRCUIT RESETED)"; | |
_log.LogWarning(msg); | |
}); | |
return circuitBreaker; | |
} | |
private async Task CircuitOpen(DelegateResult result, TimeSpan timeSpan) | |
{ | |
var msg = | |
$" OPENED CIRCUIT (CIRCUIT BREAKED): {timeSpan} |" + | |
$" WAITING: {timeSpan} |" + | |
$" STATUSCODE: {result.Result.StatusCode} |" + | |
$" REASONPHRASE: {result.Result.ReasonPhrase} |"; | |
_log.LogWarning(msg); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment