Hangfire icon indicating copy to clipboard operation
Hangfire copied to clipboard

Schedule on a specific server

Open VGBenjamin opened this issue 2 years ago • 0 comments

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,

VGBenjamin avatar Jul 04 '22 14:07 VGBenjamin