在定义策略时,我希望能够在运行时禁用或启用策略,而不是在调用站点进行操作,因为我可能有多个调用站点。
这是目前我的方法?
这是目前我的方法?
private RetryPolicy<IDisposable> GetRetryPolicy()
{
if (!this.config.DistributedLockEnabled)
{
NoOpPolicy<IDisposable> policy = Policy.NoOp<IDisposable>();
return policy;
}
RetryPolicy<IDisposable> lockPolicy = Policy
.Handle<TimeoutException>()
.OrResult<IDisposable>(d => d == null)
.WaitAndRetry(
this.config.WorkflowLockHandleRequestRetryAttempts,
attempt => TimeSpan.FromSeconds(this.config.WorkflowLockHandleRequestRetryMultiplier * Math.Pow(this.config.WorkflowLockHandleRequestRetryBase, attempt)),
(delegateResult, calculatedWaitDuration, attempt, context) =>
{
if (delegateResult.Exception != null)
{
this.logger.Information(
"Exception {0} attempt {1} delaying for {2}ms",
delegateResult.Exception.Message,
attempt,
calculatedWaitDuration.TotalMilliseconds);
}
});
return lockPolicy;
}
但是,遗憾的是,这段代码无法编译 :)
谢谢, Stephen
private ISyncPolicy<IDisposable> GetRetryPolicy() { ... }
。 - mountain traveller