

Usually a "maintenance mode" flag is designed to allow the production environment to run but prevent state change/input from regular users. What does "maintenance" mean or why does "maintenance" require the need to stop processing jobs?īecause if it's a deployment scenario we've covered that above. It's not built in but you can do it and filter out a server from consuming from a specified queue.Īnother Example: Maybe we plan to take a server down for maintenance so we pause it from processing new jobs, wait for it to finish current jobs, and then take it down. Here you're wanting to essentially "take one server out of the load" like you might with a load balancer. And i don't want to restart the servers in order to do that. (I know, I know.) I would like to pause the production server (or maybe pause the dev server) from processing jobs and let the other server handle them. Let's address the OPs original concrete scenarios:Įxample: Sometimes I have a production server and a development server pointing to the same Hangfire database so we can troubleshoot issues. All sensitive state will be designed with ACID principals and so the missing work mid-deployment will be completed after the deployment. Every web node will shut down BackgroundJobServer when recycled and Hangfire will guarantee the re-queuing and invocation of jobs that didn't complete or those that failed.

Pausing one job or a specific subset is one thing: use filters or custom logic in your job entry point.īut a top-level/ BackgroundJobServer "Stop/Start" feature makes no sense if it's to solve the deployment concern. I think the design reveals that you simply don't need to. It prevents the database or active processing when I want to shut down at any rate.Īs for a "Stop/Start" feature or workaround, one might look at the design choice and suggestion to dispose and re-create the BackgroundJobServer as "making this harder" but I don't think so. When I restart I re-create the cache flag if the stored flag exists and that does the job. The sleepers use Thread.Sleep until the cache flag is gone and then quit. I store a pause status in a list and put a flag in cache. :-)įinal edit: Creating a sleeper class and filling the workers with that did what I needed. :-) I don't see the queues as more than an attribute or filter in any of the existing classes and the db schema only has queues defined as lists of jobs with nothing for the overall queue attributes.Īlternatively perhaps the worker class could be extended so that workers can be put into a paused state or reduced to 0? There are sleep methods under BackgroundProcessContext but no documentation on what they do.Įdit: The IMonitoringAPI can be used to retrieve server details but changing the WorkersCount does nothing. If pause state is in the stored hash then generate wait jobs when the service starts but perhaps they'd still be requeued automatically if they were running at shutdown anyway.

Add an api to pause and unpause processing. Periodically check for a stored hash value to change and keep running the filler jobs until it does. Here's a crude workaround - Add a wait queue as the first priority and fill it with jobs which do nothing but run until a condition is met.
