I’m currently trying to implement the Clustering feature from Quartz to ensure, that only one node is executing the job once regardless of the amount of nodes.
My current Quartz configuration looks like this:
builder.Services.AddQuartz(options =>
{
options.SchedulerName = "DefaultSchedulerInstance";
options.SchedulerId = "AUTO";
options.UsePersistentStore(storeOptions =>
{
storeOptions.PerformSchemaValidation = true;
storeOptions.UseProperties = true;
storeOptions.RetryInterval = TimeSpan.FromSeconds(15);
storeOptions.UseNewtonsoftJsonSerializer();
storeOptions.UseDefaultThreadPool(
threadPoolOptions => threadPoolOptions.MaxConcurrency = 3);
storeOptions.UsePostgres(postgresOptions =>
{
postgresOptions.ConnectionString = CONNECTION_STRING;
postgresOptions.TablePrefix = "QRTZ_";
});
storeOptions.UseClustering(clusterOptions =>
{
clusterOptions.CheckinMisfireThreshold = TimeSpan.FromSeconds(30);
clusterOptions.CheckinInterval = TimeSpan.FromSeconds(10);
});
});
var jobKey = new JobKey(
nameof(MyRepeatableJob),
"MyRepeatableJobGroup");
options.AddJob<MyRepeatableJob>(jobBuilder => jobBuilder.WithIdentity(jobKey))
.AddTrigger(
trigger =>
trigger.ForJob(jobKey)
.StartAt(DateTime.UtcNow.AddSeconds(15))
.WithSimpleSchedule(
schedule =>
schedule.WithIntervalInSeconds(60)
.RepeatForever()));
});
builder.Services.AddQuartzHostedService(
options => options.WaitForJobsToComplete = true);
Quartz correctly selects only one node to run the job on. But anyhow it gets executed multiple times. To be specific, it executes the job as often as the amount of total nodes. I asume, that my configuration is incorrect, but I can’t find out why.
I highly appreciate any kind of help. Thanks in advance.