Last active
January 27, 2017 13:40
-
-
Save hyrmn/02782bfdc465f434ea25 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| public static class IDocumentSessionExtensions | |
| { | |
| private static readonly Policy RetryPolicy = Policy | |
| .Handle<WebException>(ex => TransientErrors.Contains(ex.Status)) | |
| .WaitAndRetry(new[] | |
| { | |
| TimeSpan.FromSeconds(1), | |
| TimeSpan.FromSeconds(2), | |
| TimeSpan.FromSeconds(3) | |
| }); | |
| private static readonly HashSet<WebExceptionStatus> TransientErrors = new HashSet<WebExceptionStatus>(new[] | |
| { | |
| WebExceptionStatus.ConnectFailure, | |
| WebExceptionStatus.ConnectionClosed, | |
| WebExceptionStatus.KeepAliveFailure, | |
| WebExceptionStatus.Pending, | |
| WebExceptionStatus.PipelineFailure, | |
| WebExceptionStatus.ProtocolError, | |
| WebExceptionStatus.ReceiveFailure, | |
| WebExceptionStatus.RequestCanceled, | |
| WebExceptionStatus.SecureChannelFailure, | |
| WebExceptionStatus.SendFailure, | |
| WebExceptionStatus.Timeout | |
| }); | |
| public static void SaveChangesWithRetry(this IDocumentSession session) | |
| { | |
| RetryPolicy.Execute(session.SaveChanges); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uses Polly to provide a reliable wrapper for raven. Useful when you're hosting on Azure.