Created
October 10, 2014 09:30
-
-
Save jkonecki/fc8df37e5642584a8c99 to your computer and use it in GitHub Desktop.
Transient error detection strategy for RavenDB using Microsoft.Practices.TransientFaultHandling application block
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
using Microsoft.Practices.TransientFaultHandling; | |
public class RavenDBTransientErrorDetectionStrategy : ITransientErrorDetectionStrategy | |
{ | |
public bool IsTransient(Exception ex) | |
{ | |
dynamic currentException = ex; | |
while(currentException != null) | |
{ | |
if (this.IsExceptionTransient(currentException)) | |
return true; | |
currentException = currentException.InnerException; | |
} | |
return false; | |
} | |
private bool IsExceptionTransient(Exception ex) | |
{ | |
return false; | |
} | |
private bool IsExceptionTransient(TimeoutException ex) | |
{ | |
return true; | |
} | |
private bool IsExceptionTransient(WebException ex) | |
{ | |
var transientStatuses = 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 | |
}); | |
return transientStatuses.Contains(ex.Status); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What's been your impl strategy? Wrap every call to session.SaveChanges() or subclass DocumentSession and internally wrap the call or something completely different?