Support for Single Instance, Continuous Tasks?


#1

What does Hangfire offer for single instance, continuous tasks? I have a system that has several jobs that need to always run, and can only have one instance running across all servers. The job executes with an indefinite length, until a change in configuration is required.

My exact case is connecting to a server that streams data to us over a TCP we open to them. I can only have one TCP connection open at any time. So when the process starts up, it connects, sends the config parameters and just receives data “forever”. Until someone adds a new record, at which point I close the connection, and reconnect with new parameters.

Right now I have a hacky system that starts a new thread if the web.config indicates this instance is the chosen one, and a bunch of invasive code to detect changes and restart. It’s basically a while(true) loop.

Can Hangfire make this simpler? For the continuous part, I guess I can just have a job with unlimited retries, no expiration, then just fail/abort every time I need to restart. But, that’s a bit ugly eh? What about notifying the server that’s running that job, what facilities exist for that?

Thanks!


Allow for cron to include seconds
#2

I have plans to open the infrastructural classes Hangfire uses for executing long-running processes, but they are internal so far. For now, you can use ServerSupervisor, IServerComponent and AutomaticRetryComponentWrapper source code to achieve it. Please see the Worker class for an example.


#3

Any update if this happens to be already available?

Would love to launch some long running tasks with hangfire :slight_smile:


#4

I’d like to see continuous job support too. I currently have continuous Azure Webjobs running and also Hangfire jobs. Consolidating for management would be nice.