根据 Hangfire 0.8.2 announcement post , Hangfire 有一个 DisableConcurrentExecution
过滤器,当应用于一个方法时,它会阻止该方法的多个实例同时执行。
DisableConcurrentExecution
过滤器采用 timeoutInSeconds
int 参数。来自链接文章中的示例:
[DisableConcurrentExecution(timeoutInSeconds: 10 * 60)]
public void SomeMethod()
{
// Operations performed inside a distributed lock
}
我的问题是:给定一个正在等待为 DisableConcurrentExecution
过滤方法获取锁的作业,当该作业等待的时间超过 timeoutInSeconds< 时会发生什么
值?
最佳答案
我最近对此进行了测试。该作业实例在仪表板中被记录为失败,并列出了表明在等待独占锁时超时已过期的异常。
您会看到以下异常:
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)
关于c# - Hangfire 禁用并发执行 : What happens when the timeout expires?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40515961/