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

Hangfire DisableConcurrentExecution: What happens when the timeout expires?

根据 Hangfire 0.8.2 announcement post,Hangfire 有一个 DisableConcurrentExecution 过滤器,当应用于一个方法时,可以防止该方法的多个实例同时执行。

DisableConcurrentExecution 过滤器采用 timeoutInSeconds 整型参数。来自链接文章中的示例:

[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)