我有一个网络服务,当发布到,会在Hangfire中排队下载图片,这样如果图片下载失败,Hangfire会自动重试:
[AutomaticRetry(Attempts = 5, OnAttemptsExceeded = AttemptsExceededAction.Delete)]
public static void DownloadImage(string url)
{
...
}
每次发布Web服务时,它都会添加一些调用此方法的后台作业,如下所示:
Hangfire.BackgroundJob.Enqueue(() => Downloader.DownloadImage(o.SourceURL));
我所看到的是,第一个后台作业成功,其余部分在RAPID继承中失败,即在一秒钟内,比如100个排队的作业将失败分配5次(根据AutomaticRetry
属性)
Hangfire任务中的错误是:
Hangfire.Storage.DistributedLockTimeoutException
Timeout expired. The timeout elapsed prior to obtaining a distributed lock on the 'HangFire:Downloader.DownloadImage' resource.
Hangfire.Storage.DistributedLockTimeoutException: Timeout expired. The timeout elapsed prior to obtaining a distributed lock on the 'HangFire:Downloader.DownloadImage' resource.
at Hangfire.SqlServer.SqlServerDistributedLock.Acquire(IDbConnection connection, String resource, TimeSpan timeout)
at Hangfire.SqlServer.SqlServerDistributedLock..ctor(SqlServerStorage storage, String resource, TimeSpan timeout)
at Hangfire.SqlServer.SqlServerConnection.AcquireDistributedLock(String resource, TimeSpan timeout)
at Hangfire.DisableConcurrentExecutionAttribute.OnPerforming(PerformingContext filterContext)
at Hangfire.Server.BackgroundJobPerformer.InvokePerformFilter(IServerFilter filter, PerformingContext preContext, Func`1 continuation)