Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class AzureFriendlyReplicationInformer : ReplicationInformer
{
public AzureFriendlyReplicationInformer(DocumentConvention conventions)
: base(conventions)
{
}
public override bool ShouldExecuteUsing(string operationUrl, int currentRequest, string method, bool primary)
{
if (primary == false)
AssertValidOperation(method);
var failureCounter = GetHolder(operationUrl);
if (failureCounter.Value == 0 || failureCounter.ForceCheck)
{
failureCounter.LastCheck = SystemTime.UtcNow;
return true;
}
if (currentRequest % CheckRepititionRate(failureCounter.Value) == 0)
{
failureCounter.LastCheck = SystemTime.UtcNow;
return true;
}
if ((SystemTime.UtcNow - failureCounter.LastCheck) > conventions.MaxFailoverCheckPeriod)
{
failureCounter.LastCheck = SystemTime.UtcNow;
return true;
}
return false;
}
private int CheckRepititionRate(long value)
{
if (value < 10000)
return 1000;
if (value < 100000)
return 10000;
return 100000;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment