根据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)