How to manually start/stop queue processing

I use Hangfire in aspnet core. It starts by itself once I call UseHangfireServer() and works until the app is shut down. But I need more fine-grained control. Specific queues should be executed only if there is open connection to remote server at the moment. This connection is not guaranteed.

What I want is to have N queues and start/stop processing of them depending on server connection. so I can stop the processing queue “server1_tasks” if server1 is not reachable at the moment and resume the queue once it’s back. It seems more logical for me than filtering jobs before execution and requeueing them.

Is it possible?

You can write your own AutomaticRetryAttribute with some periodically poll interval (for example, 5 sec).
And try to execute your background job. If there is an exception because of lost server connection, job will stop and execute after poll interval again.

It’s not push but poll machanism, not beautiful solution, but it should work.