I have a couple instances of Hangfire running on two servers using the same database. Each instance submits jobs to be run based on some criteria based on server name so that no two instances run the same job. I noticed that they are running the same jobs which means when an instance is running it’s picking any job in the queue in the database regardless if it submitted the job or not. I thought in the latest version 1.6.x, each job is unique. It seems this doesn’t mean it runs only on the instance that created it?
How do I get each instance to run jobs it submitted only?
Hi, it looks like you are developing against the Hangfire idea. That is very correct when more servers receive the jobs from same queue - by this you achieve scalability of the environment. To avoid running the same job twice on two different Servers you can use the DisableConcurrency attribute.
Running jobs on selected instance only will give you one dangerous effect - in case one of more servers is down, some of your jobs will not be executed - I advise to rethink your strategy.
to answer your original question, if you insist, you can achieve this by creating the jobs in custom specified queue. You can configure each server to work on jobs only from certain queues. So each server has his own queue. But as said before, this does not seem to be good idea.