Old server tries to process new queue

I have two servers behind one load balancer.

I published a new version of my web application to one specific server. This new server has the following code:

app.UseHangfire(config =>
{
    config.UseSqlServerStorage("foo");
    config.UseServer("bar", "default");
});

The new server has this function too:

[Queue("bar")]
[AutomaticRetry(Attempts = 3)]
public static void ProcessFile(string path)
{
    ...
}

I understand that the new server is the one in charge of processing jobs of the bar queue because the old server doesn’t have the config.UseServer("bar", "default"); line.
The old server calls that function with one argument: config.UseServer("default");.

But for some reason, the old server is trying to process the jobs of the bar queue and an exception is thrown because that server doesn’t have the ProcessFile function.

Any idea about what I am doing wrong?

Thanks!

I’ve been experiencing this too. I removed the server from the underlying database so that it no longer shows in the active server list. However, when I queue a job it’s been handled by the old server, which from looking at the database, Hangfire should no longer know about. It’s very strange!

I was missing something: every single server is in charge of enqueueing jobs. In order to enqueue a job, Hangfire needs to have a reference to the assembly that contains the

[Queue("bar")] [AutomaticRetry(Attempts = 3)] public static void ProcessFile(string path) { ... }

method.