How to catch and handle Distributed Lock Timeout Exception

We have a recurring job that is set to run every 1min. but sometimes that job takes longer than 1 min. to run and we only want 1 of them to run at a time. I have placed a DisableConcurrentExecution attribute on the method that is called with a timeout of 0 because I don’t want them to be queued up in processing. Effectively what we want is for the job to run every minute and if the job is already running, just skip queuing it and wait for the next 1min. trigger.

The code is “working” but I would like to know how I can catch the “DistributedLockTimeoutException” so that I can ignore it and not have it spit out in the logs and then optionally (though not important) consider not having the job go to “Failed” but rather just either not enqueue any record of it or say that it suceeded with an additional message saying that it was skipped.

I assumed that I need some sort of JobFilter but I can’t quite figure out from the Documentation how to achieve the desired outcome and any assistance would be appreciated. I can see in “OnStateElection” that it is set to enter the FailedState and I can see the exception but I don’t know how to stop that exception from bubbling up and also not sure if I can tell it to go to the succeeded state.

1 Like