Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Quartz StartupDelay option #3454

Merged
merged 3 commits into from
Apr 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Quartz;
using Quartz.Impl;
using Quartz.Spi;
Expand All @@ -20,9 +21,15 @@ public override void ConfigureServices(ServiceConfigurationContext context)

public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
var options = context.ServiceProvider.GetRequiredService<IOptions<AbpQuartzPreOptions>>().Value;

_scheduler = context.ServiceProvider.GetService<IScheduler>();
_scheduler.JobFactory = context.ServiceProvider.GetService<IJobFactory>();
_scheduler.Start();

if (options.StartDelay != null && options.StartDelay.Ticks > 0)
_scheduler.StartDelayed(options.StartDelay);
else
_scheduler.Start();
olicooper marked this conversation as resolved.
Show resolved Hide resolved
olicooper marked this conversation as resolved.
Show resolved Hide resolved
}

public override void OnApplicationShutdown(ApplicationShutdownContext context)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
using System.Collections.Specialized;
using System;
using System.Collections.Specialized;

namespace Volo.Abp.Quartz
{
public class AbpQuartzPreOptions
{
/// <summary>
/// The quartz configuration. Available properties can be found within Quartz.Impl.StdSchedulerFactory.
/// </summary>
public NameValueCollection Properties { get; set; }
/// <summary>
/// How long Quartz should wait before starting. Default: 0.
/// </summary>
public TimeSpan StartDelay { get; set; }

public AbpQuartzPreOptions()
{
Properties = new NameValueCollection();
StartDelay = new TimeSpan(0);
}
}
}