Normand Bedard
Normand Bedard

Reputation: 2685

Hangfire - Recurring job with specified queue name

I have two server, ServerA and ServerB. They share the same hangfire database. I have two jobs, JobA and JobB.

On ServerA, I use:

RecurringJob.AddOrUpdate(
            "JobA",
            () => new JobA().Execute(),
            this._configuration.Schedule, queue: "A");

On ServerB, I use:

  RecurringJob.AddOrUpdate(
            "JobB",
            () => new JobB().Execute(),
            this._configuration.Schedule, queue: "B");

The problem is that each jobs is "Enqueued" in the "Job" table, they are never executed.

If I remove the queue override in the "AddOrUpdate" method, jobs are executed (obviously without queue configured).

Something missing? How configure recurring jobs with queue configuration?

Upvotes: 1

Views: 4504

Answers (2)

Normand Bedard
Normand Bedard

Reputation: 2685

Code was missing...

ServerA:

var options = new BackgroundJobServerOptions
{
  Queues = new[] { "A" }
};

this._backgroundJobServer = new BackgroundJobServer(options);

ServerB:

var options = new BackgroundJobServerOptions
{
  Queues = new[] { "B" }
};

this._backgroundJobServer = new BackgroundJobServer(options);

Upvotes: 3

Tejas Patel
Tejas Patel

Reputation: 1447

Solution - might help someone with similar issue:

app.UseHangfireServer(new BackgroundJobServerOptions
{
     // queue name must be in lowercase
     Queues = new[] { "qname" } //This will setup the server to only process qname queues 
});

RecurringJob.AddOrUpdate(
    () => new JobB().Execute(),
    Cron.Hourly(5),
    null,
    "qname");

Upvotes: 2

Related Questions