Skip to content

Instantly share code, notes, and snippets.

@hyrmn
Last active January 27, 2017 13:40
Show Gist options
  • Select an option

  • Save hyrmn/02782bfdc465f434ea25 to your computer and use it in GitHub Desktop.

Select an option

Save hyrmn/02782bfdc465f434ea25 to your computer and use it in GitHub Desktop.
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);
}
}
@hyrmn
Copy link
Copy Markdown
Author

hyrmn commented Nov 9, 2015

Uses Polly to provide a reliable wrapper for raven. Useful when you're hosting on Azure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment