From a3046abd125f3ed6e5203730f2b2b42a18803905 Mon Sep 17 00:00:00 2001 From: Vladimir Pecanac Date: Wed, 16 Sep 2026 15:24:54 +0200 Subject: [PATCH] Quartz.NET tutorial sample: move to Quartz.NET 4.1.0 Quartz.NET 4 changes the job signature, merges three packages into one and removes the interval shorthand, so the sample no longer compiles as written. - Quartz 3.19.1 to 4.1.0. Quartz.Extensions.Hosting and Quartz.Serialization.Json are dropped: both publish empty forwarding packages on 4.1.0, and hosting, dependency injection and the System.Text.Json serializer are in Quartz itself. - Microsoft.Data.SqlClient 6.1.1 to 7.0.3, the newest stable. - IJob.Execute moves to ValueTask plus a CancellationToken, with the default on the token so both existing tests keep compiling unchanged. - WithIntervalInSeconds(5) becomes WithInterval(TimeSpan.FromSeconds(5)). - UseNewtonsoftJsonSerializer() becomes UseSystemTextJsonSerializer(). - ScheduleJob passes ScheduleJobOptions.Replacing. With a persistent store the job definition is already in the database on the second start, and without this the sample throws ObjectAlreadyExistsException before the scheduler runs. Checked against SQL Server 2022 in Docker: one start on an empty database, then two restarts, all clean. dotnet build -c Release: 0 warnings, 0 errors. dotnet test: 2 of 2 passed. --- .../Quartz.NET/Quartz.NET/BackgroundJob.cs | 2 +- dotnet-client-libraries/Quartz.NET/Quartz.NET/Program.cs | 6 +++--- .../Quartz.NET/Quartz.NET/Quartz.NET.csproj | 6 ++---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/dotnet-client-libraries/Quartz.NET/Quartz.NET/BackgroundJob.cs b/dotnet-client-libraries/Quartz.NET/Quartz.NET/BackgroundJob.cs index bb023c4b7e..2ad126dcd2 100644 --- a/dotnet-client-libraries/Quartz.NET/Quartz.NET/BackgroundJob.cs +++ b/dotnet-client-libraries/Quartz.NET/Quartz.NET/BackgroundJob.cs @@ -1,7 +1,7 @@ namespace Quartz.NET; public class BackgroundJob : IJob { - public async Task Execute(IJobExecutionContext context) + public async ValueTask Execute(IJobExecutionContext context, CancellationToken cancellationToken = default) { var jobDataMap = context.MergedJobDataMap; diff --git a/dotnet-client-libraries/Quartz.NET/Quartz.NET/Program.cs b/dotnet-client-libraries/Quartz.NET/Quartz.NET/Program.cs index 6bd1b7ac3d..cce270a1e0 100644 --- a/dotnet-client-libraries/Quartz.NET/Quartz.NET/Program.cs +++ b/dotnet-client-libraries/Quartz.NET/Quartz.NET/Program.cs @@ -14,7 +14,7 @@ .WithIdentity(name: "SimpleRepeatingTrigger", group: "TriggerGroup") .WithSimpleSchedule(o => o .RepeatForever() - .WithIntervalInSeconds(5)) + .WithInterval(TimeSpan.FromSeconds(5))) .Build(); var host = Host.CreateDefaultBuilder() @@ -25,7 +25,7 @@ opt.UsePersistentStore(s => { s.UseSqlServer("Server=localhost,1433;Database=Quartz;User Id=sa;Password=;Encrypt=False;"); - s.UseNewtonsoftJsonSerializer(); + s.UseSystemTextJsonSerializer(); }); }); services.AddQuartzHostedService(opt => @@ -37,5 +37,5 @@ var schedulerFactory = host.Services.GetRequiredService(); var scheduler = await schedulerFactory.GetScheduler(); -await scheduler.ScheduleJob(job, trigger); +await scheduler.ScheduleJob(job, trigger, ScheduleJobOptions.Replacing); await host.RunAsync(); \ No newline at end of file diff --git a/dotnet-client-libraries/Quartz.NET/Quartz.NET/Quartz.NET.csproj b/dotnet-client-libraries/Quartz.NET/Quartz.NET/Quartz.NET.csproj index 8ce967ea13..e81fe823c2 100644 --- a/dotnet-client-libraries/Quartz.NET/Quartz.NET/Quartz.NET.csproj +++ b/dotnet-client-libraries/Quartz.NET/Quartz.NET/Quartz.NET.csproj @@ -8,11 +8,9 @@ - + - - - +