diff --git a/LiteCharms.Extensions/LiteCharms.Extensions.csproj b/LiteCharms.Extensions/LiteCharms.Extensions.csproj index 719beaf..2eb0aa9 100644 --- a/LiteCharms.Extensions/LiteCharms.Extensions.csproj +++ b/LiteCharms.Extensions/LiteCharms.Extensions.csproj @@ -22,7 +22,7 @@ LiteCharms.Extensions - 1.0.17 + 1.0.18 Khwezi Mngoma Lite Charms (PTY) Ltd Extension components for Lite Charms applications. diff --git a/LiteCharms.Extensions/Quartz.cs b/LiteCharms.Extensions/Quartz.cs index 471f92d..a8ee941 100644 --- a/LiteCharms.Extensions/Quartz.cs +++ b/LiteCharms.Extensions/Quartz.cs @@ -7,6 +7,41 @@ public static class Quartz { private const string databaseConfigName = "PostgresScheduler"; + public static IServiceCollection AddQuartzSchedulerClient(this IServiceCollection services, string schedulerName, string schedulerId, IConfiguration configuration) + { + var connectionString = configuration.GetConnectionString(databaseConfigName); + + services.ConfigureCommon(); + + services.AddQuartz(config => + { + config.SchedulerName = schedulerName; + config.SchedulerId = schedulerId; + + config.UseSimpleTypeLoader(); + config.UseDefaultThreadPool(options => options.MaxConcurrency = 0); + config.UseTimeZoneConverter(); + + config.UsePersistentStore(storage => + { + storage.PerformSchemaValidation = false; + + storage.UseSystemTextJsonSerializer(); + storage.SetProperty("quartz.jobStore.clustered", "true"); + storage.SetProperty("quartz.jobStore.tablePrefix", "quartz_"); + + storage.UsePostgres(connectionString!); + storage.UseClustering(cluster => + { + cluster.CheckinInterval = TimeSpan.FromSeconds(30); + cluster.CheckinMisfireThreshold = TimeSpan.FromSeconds(2); + }); + }); + }); + + return services; + } + public static IServiceCollection AddQuartzScheduler(this IServiceCollection services, string schedulerName, string schedulerId, IConfiguration configuration) { var connectionString = configuration.GetConnectionString(databaseConfigName);