Bad codebase continue to run in Hangfire. How do i stop it?

Ok, so this post to the forum is literally my last resort here. I have gotten myself into a bit of a pickle with Hangfire and need some solutions to stop it doing what it is doing.

Firstly, i’m working with Hangfire in my development environment, using Redis as my storage.

We had a bit of code from one of my developers that has a loop and under certain conditions the logic within the loop failed but did not break out of the loop. In this scenario it writes infinite error logs to the DB using hangfire for this. Obviously we are in the midst of development so this was identified and already patched up.However, now, every time i start the application on my development machine, the Hangfire dashboard immediately lights up with over 32000 thousand enqueued jobs that it immediately begins processing and writing to our DB.

Is there no way to wipe out the storage of all enqueued items? I mean this is creating a bit of a mess and the only way to stop it is to not run our application. Surely there should be some reset mechanism in place that can be used while working with Hangfire in development?

Also, how does Hangfire manage code changes? What are the best practices with working with Hangfire in development and then moving to Production? If code changes does Hnagfire wipe all pending jobs? Is there any explanation of how Hangfire handles code base changes? And how should we be setting up Hangfire in development vs. production to avoid code base conflicts?

Code changes do not wipe pending jobs. That one was easiest to answer. All the jobs and their data are in the storage.

Which brings me (and perhaps I am oversimplifying here) to solution #1 of your problem, remove the hangfire data from redis and/or start fresh?

Alternatively if you need be more selective, you can always delete jobs via the API. (Dashboard too but with the numbers you mention it might be a lot of work)

Again grossly oversimplifying here but something along the lines of :


Using (var connection = JobStorage.Current.GetConnection())
{
foreach (var recurringJob in connection.GetRecurringJobs())
{
RecurringJob.RemoveIfExists(recurringJob.Id);
}
}

1 Like

Thanks for the reply. I’ll give this a go…