Why do I often get a TimeoutException?

Hi

I am using hangfire to run a job that generates some xml files. The job is activated from a web.api rest endpoint that is called when some data is changed in the DB. On the job I have [DisableConcurrentExecution(timeoutInSeconds: 600)] as I only want to run one instance of the job at a time. On the web.api controller I have this code:

        var hangfireApi = JobStorage.Current.GetMonitoringApi();
        if (hangfireApi.ProcessingCount() <= 1 &&hangfireApi.ScheduledCount() == 0 && hangfireApi.EnqueuedCount("default") == 0)
        {
            BackgroundJob.Enqueue<GenerateXmlTaskHandler>(x => x.GenerateAll());
        }       

The intention is to max have 1 job running and max 1 job “in line”. That way, when the database is updated, I avoid scheduling a new job if one is already “in line” as the one “in line” will handle all data when it is started.

This seems to work, but my jobs often give up because of a Hangfire.Storage.DistributedLockTimeoutException. Does anyone know why that happens? Please let me know if some information is missing or if something is unclear