Hangfire hangs if you try and delete a job that doesn't exist, i.e if jobId isn't in Hangfire.Job
BackgroundJob.Delete(jobId);
Is there any way of checking if a job exists before trying to delete it?
Try using the monitoring API (JobStorage.Current.GetMonitoringApi()
), there is a possibility to get job details or list of jobs.
Complete code example:
var monitoringApi = JobStorage.Current.GetMonitoringApi();
var deletedJobs = monitoringApi.DeletedJobs(0, 10);
If you want to get queued items:
// If no queue name was defined somewhere, probably this will be "default".
// If no items have been queued, then the queue won't exist, and it will error here.
var queue = monitoringApi.Queues().First().Name;
var enqueud jobs = monitoringApi.EnqueuedJobs(queue, 0, 10);
There is no need to do this anymore, as the bug causing Hangfire to hang has been fixed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With