Hi I am trying to delete a scheduled job in hangfire using BackgroundJob.Delete. However there is a chance that the scheduled job has been run and no longer exists anywhere in hangfire. When that happens I get the following exception:
Hangfire.BackgroundJobClientException
State change of a background job failed. See inner exception for details
Hangfire.BackgroundJobClientException: State change of a background job failed. See inner exception for details —> Hangfire.Storage.DistributedLockTimeoutException: Timeout expired. The timeout elapsed prior to obtaining a distributed lock on the ‘HangFire:job:105115:state-lock’ 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.States.BackgroundJobStateChanger.ChangeState(StateChangeContext context)
at Hangfire.BackgroundJobClient.ChangeState(String jobId, IState state, String expectedState)
— End of inner exception stack trace —
at Hangfire.BackgroundJobClient.ChangeState(String jobId, IState state, String expectedState)
at Hangfire.BackgroundJobClientExtensions.Delete(IBackgroundJobClient client, String jobId, String fromState)
The job referenced 105115 was no longer valid in hangfire, this sits for awhile before throwing an exception. Should I be checking if the job exists prior to deletion, and if so how does one go about doing that?
I am running v1.5 using MSMQ and SQL server
Thanks
Monte