Hangfire Discussion

Using One hangfire DB for multiple applications


#1

I am facing some weird issues of Hangfire something like below when I use two applications to point one Hangfire DB. Any specific process I need to follow for the Hangfire DB?

{“FailedAt”:“2015-01-15T14:46:56.0152366Z”,“ExceptionType”:“System.IO.FileNotFoundException”,“ExceptionMessage”:“Could not load file or assembly ‘CCIActivityWorkflow, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ or one of its dependencies. The system cannot find the file specified.”,“ExceptionDetails”:“System.IO.FileNotFoundException: Could not load file or assembly ‘CCIActivityWorkflow, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ or one of its dependencies. The system cannot find the file specified.\r\nFile name: ‘CCIActivityWorkflow, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’\r\n at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type)\r\n at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)\r\n at System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)\r\n at Hangfire.Storage.InvocationData.Deserialize()\r\n\r\nWRN: Assembly binding logging is turned OFF.\r\nTo enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.\r\nNote: There is some performance penalty associated with assembly bind failure logging.\r\nTo turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].\r\n”}


Multiple Hangfire service points to single Hangfire database
#2

Well… it actually not supported ‘by default’.

You have to make sure that the job is executed on the application where it was scheduled, otherwise HangFire can not execute the job, since it can not find the Job’s method,

I’ve come up with a solution for sharing one hangfire database accross multiple applications.
Please see:


#3

@rikbosch Thank You! I implemented this on the application. I hope it will turn out well. I referred the below hangfire article for this which is same as you have mentioned.

http://docs.hangfire.io/en/latest/background-processing/running-multiple-server-instances.html


#4

For those using different queues for different machines/application/instances etc, be aware that clicking “Requeue Job” in the Hangfire admin on succeeded or failed jobs from custom queues will dump the job back into the “Default” queue, in which case you can’t be sure which application will process it next.

Apologies if this was corrected recently.


#5

I’ve got a slightly different setup. I’ve got 3 servers and 2 applications. Each server runs both applications - originally, I was constantly running into this same issue since both were using the default queue and picking up each other’s jobs. Now I’ve got a separate queue per application (let’s call them App1 and App2). App1’s jobs always seem to get picked up by App1, but App2’s jobs seem to get picked up by App1 sometimes. Awfully mysterious.

Looking at the “Servers” section of the dashboard, there’s nothing listening to the DEFAULT queue and sure enough I have 6 total entries - 3 servers * 2 applications each hooked up to the correct queue. To clarify, each server is running each application in a separate process. The name in the Servers section is hostname + port number, which is unique. Any ideas?


#6

I want to run the multiple instance of the hangfire on different machines say Server1, Server2 and Server3. Now I wish to run jobs on specific Server. Say job1 and job3 on Server1, job2 on Server2 and Job4 on Server 3. How can I achieve this.


#7

The original question is posted in 2015 but Is this issue already resolved in latest version of hangfire? I noticed If i use Sql db then hangfire creates [Server] table which has unique ID column. Can we now use multiple hangfire instances with single DB?