How to query whether all jobs are completed using monitoring api?

Tags: #<Tag:0x00007f783a443720>


In our integration tests, I am calling an API that kicks off a set of Hangfire background work. I’d like to wait for all job processing to complete before continuing. I’ve found the MonitoringApi and am checking every status I can to ensure jobs are complete, but this does not seem to work.

var queues = _monitoringApi.Queues();
            return queues.All(queue => queue.FirstJobs.Count == 0 && _monitoringApi.EnqueuedCount(queue.Name) == 0) &&
                   _monitoringApi.ProcessingCount() == 0 && _monitoringApi.FailedCount() == 0;