Hangfire DisableConcurrentExecution:超时到期后会发生什么?

Jon*_*der 14 c# hangfire

根据Hangfire 0.8.2公告帖子,Hangfire有一个DisableConcurrentExecution过滤器,当应用于某个方法时,会阻止该方法的多个实例同时执行.

DisableConcurrentExecution过滤器采用一个timeoutInSecondsint参数.从链接文章中的示例:

[DisableConcurrentExecution(timeoutInSeconds: 10 * 60)]
public void SomeMethod()
{
    // Operations performed inside a distributed lock
}
Run Code Online (Sandbox Code Playgroud)

我的问题是:当一个等待获取锁定DisableConcurrentExecution的作业的时候,作业等待的时间超过了这个timeoutInSeconds值,会发生什么?

Nat*_*ank 21

我最近测试过.该作业实例在仪表板中记录为失败,并列出了异常,表示在等待独占锁定时超时已到期.

您将看到以下异常:

Hangfire.Storage.DistributedLockTimeoutException: Timeout expired. The timeout elapsed prior to obtaining a distributed lock on the 'xxx' resource.
    at Hangfire.SqlServer.SqlServerDistributedLock.Acquire(IDbConnection connection, String resource, TimeSpan timeout)
Run Code Online (Sandbox Code Playgroud)

  • 在这里,您可以获得更详细的异常信息(对于缺少格式化而道歉):Hangfire.Storage.DistributedLockTimeoutException:超时已到期.在'xxx'资源上获得分布式锁之前经过的超时时间.在Hangfire.SqlServer.SqlServerDistributedLock.Acquire(IDbConnection连接,字符串资源,TimeSpan超时) (2认同)