From 8df24a62fd35acd64b7f1f79a8c30f74c6d20805 Mon Sep 17 00:00:00 2001 From: Oliver Cooper Date: Thu, 2 Apr 2020 17:44:17 +0100 Subject: [PATCH 1/2] Add Quartz StartupDelay option. --- .../Volo/Abp/Quartz/AbpQuartzModule.cs | 9 ++++++++- .../Volo/Abp/Quartz/AbpQuartzPreOptions.cs | 11 ++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.Quartz/Volo/Abp/Quartz/AbpQuartzModule.cs b/framework/src/Volo.Abp.Quartz/Volo/Abp/Quartz/AbpQuartzModule.cs index c16ab14f4d..615009f914 100644 --- a/framework/src/Volo.Abp.Quartz/Volo/Abp/Quartz/AbpQuartzModule.cs +++ b/framework/src/Volo.Abp.Quartz/Volo/Abp/Quartz/AbpQuartzModule.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using Quartz; using Quartz.Impl; using Quartz.Spi; @@ -20,9 +21,15 @@ namespace Volo.Abp.Quartz public override void OnApplicationInitialization(ApplicationInitializationContext context) { + var options = context.ServiceProvider.GetRequiredService>().Value; + _scheduler = context.ServiceProvider.GetService(); _scheduler.JobFactory = context.ServiceProvider.GetService(); - _scheduler.Start(); + + if (options.StartDelay != null && options.StartDelay.Ticks > 0) + _scheduler.StartDelayed(options.StartDelay); + else + _scheduler.Start(); } public override void OnApplicationShutdown(ApplicationShutdownContext context) diff --git a/framework/src/Volo.Abp.Quartz/Volo/Abp/Quartz/AbpQuartzPreOptions.cs b/framework/src/Volo.Abp.Quartz/Volo/Abp/Quartz/AbpQuartzPreOptions.cs index e86f993d1d..9e48744d96 100644 --- a/framework/src/Volo.Abp.Quartz/Volo/Abp/Quartz/AbpQuartzPreOptions.cs +++ b/framework/src/Volo.Abp.Quartz/Volo/Abp/Quartz/AbpQuartzPreOptions.cs @@ -1,14 +1,23 @@ -using System.Collections.Specialized; +using System; +using System.Collections.Specialized; namespace Volo.Abp.Quartz { public class AbpQuartzPreOptions { + /// + /// The quartz configuration. Available properties can be found within Quartz.Impl.StdSchedulerFactory. + /// public NameValueCollection Properties { get; set; } + /// + /// How long Quartz should wait before starting. Default: 0. + /// + public TimeSpan StartDelay { get; set; } public AbpQuartzPreOptions() { Properties = new NameValueCollection(); + StartDelay = new TimeSpan(0); } } } From b0f954036be466f40c35166ab321118429d24826 Mon Sep 17 00:00:00 2001 From: Oliver Cooper Date: Fri, 3 Apr 2020 07:30:40 +0000 Subject: [PATCH 2/2] Added braces and removed null check on StartDelay. --- .../src/Volo.Abp.Quartz/Volo/Abp/Quartz/AbpQuartzModule.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.Quartz/Volo/Abp/Quartz/AbpQuartzModule.cs b/framework/src/Volo.Abp.Quartz/Volo/Abp/Quartz/AbpQuartzModule.cs index 615009f914..ccd0327ecf 100644 --- a/framework/src/Volo.Abp.Quartz/Volo/Abp/Quartz/AbpQuartzModule.cs +++ b/framework/src/Volo.Abp.Quartz/Volo/Abp/Quartz/AbpQuartzModule.cs @@ -26,10 +26,14 @@ namespace Volo.Abp.Quartz _scheduler = context.ServiceProvider.GetService(); _scheduler.JobFactory = context.ServiceProvider.GetService(); - if (options.StartDelay != null && options.StartDelay.Ticks > 0) + if (options.StartDelay.Ticks > 0) + { _scheduler.StartDelayed(options.StartDelay); + } else + { _scheduler.Start(); + } } public override void OnApplicationShutdown(ApplicationShutdownContext context)