We are leaving Russia. We are against aggression and war with Ukraine. It is a tragedy for our nations, it is a nightmare

Schedule on a specific server

Hello,

I am using Hangfire version 1.7.30.
I have two servers: “FRONTEND Server” and “BACKEND Server”, I have set the options of each server to only process the queue ith the same name with this:

var options = new BackgroundJobServerOptions
{
    Queues = new[] { HangfireQueue.BACKEND },
    ServerName = "BACKEND"
};
appBuilder.UseHangfireServer(options);

So in the dashboard I see the two servers and I see that the queue is well assigned.

Now I need to schedule a task but I need to be sure that the BACKEND server will handle it (resource access issue).
So, I enqueue like this:

BackgroundJob.Schedule<IManietCustomIndexJsonLabel>(
                    x => x.Label_Unpublish_After(label.DocumentGUID),
                    delay);

And my method is

[Queue(HangfireQueue.BACKEND)]
public void Label_Unpublish_After(Guid documentGUID)
{
    // do something here
}

When I take a look at the server I see that the tasks is scheduled on both servers and of course the wrong server take my task.
How could I do to avoid it?

Regards,

Hi Benjamin,

Is your qeues name “HangfireQueue.BACKEND” in lowercase?

The documentation says:
“Queue name argument formatting
The Queue name argument must consist of lowercase letters, digits, underscore, and dash (since 1.7.6) characters only.”

Configuring Job Queues — Hangfire Documentation.