Hi
I have a problem with hangfire queues. I use HF to trigger some background sync processes in the Net Core application using SqlServer
I have 2 queues. Lets call them “1ststep” and “2ndstep”.
For each queue I have defined a several jobs. Jobs inside the “1ststep” queue are triggered every 5th minute, while jobs inside the “2ndstep” queue are triggered every 10th minute. Which means there will be an overlap at some point.
When it comes to that moment of overlap, I want the jobs to be done in the order defined by the queue, which means that I want all the jobs from the queue named “1ststep” to be executed first, followed by all the jobs from the queue named “2ndstep”.
I did the whole hangfire setup inside the Startup.cs file. I defined all possible queues:
services.AddHangfireServer(options =>
{
options.Queues = new[] { "1ststep", "2ndstep", "default" };
});
and registered all the necessary jobs to which I assigned to selected queue:
recurringJobs.AddOrUpdate("Job1", Job.FromExpression<Class1>(x => x.Method1()), "*/5 * * * *", tzi, "1ststep");
recurringJobs.AddOrUpdate("Job2", Job.FromExpression<Class1>(x => x.Method2()), "*/5 * * * *", tzi, "1ststep");
recurringJobs.AddOrUpdate("Job3", Job.FromExpression<Class1>(x => x.Method3()), "*/5 * * * *", tzi, "1ststep");
recurringJobs.AddOrUpdate("Job5", Job.FromExpression<Class2>(x => x.Method1()), "*/10 * * * *", tzi, "2ndstep");
recurringJobs.AddOrUpdate("Job6", Job.FromExpression<Class2>(x => x.Method2()), "*/10 * * * *", tzi, "2ndstep");
When I start the application and when in a given time interval there is an overlap of jobs from 2 different queues, they are all executed at the same time. There is no priority between 2 different queues where job from “1ststep” queue will be executed first and than jobs from queue “2ndstep”
Is it even possible to have job execution priority based on queue value or am I doing something wrong ?
I even tried using QueueAttribute
on method, same result.
I can limit Worker count with: options.WorkerCount = 1 but then each job will be executed one by one and not in batch (1 batch for each queue) and that takes time.