Skip to content

Latest commit

 

History

History
32 lines (22 loc) · 1.12 KB

README.md

File metadata and controls

32 lines (22 loc) · 1.12 KB

ASP.NET Core extensions for Quartz.NET

status badge

Usage example

In Startup.cs:

    /// Register scheduler and jobs for DI ///
    public void ConfigureServices(IServiceCollection services) {
      // ...
      services.UseQuartz(typeof(HelloJob), typeof(HommaJob));
    }
    
    public void Configure(IApplicationBuilder app, IHostingEnvironment env) {

      var configuration = app.ApplicationServices.GetService<IOptions<AppConfig>>();
      var parameters = configuration.Value;
      var trigger = TriggerBuilder.Create()
        .WithIdentity(nameof(HelloJob))
        .WithCalendarIntervalSchedule(x => x.WithIntervalInMinutes(parameters.HelloJobIntervalInMinutes).PreserveHourOfDayAcrossDaylightSavings(true))
        .Build();

      // Fetch IScheduler whenever afterwards from DI container and configure schedules for jobs
      var scheduler = app.ApplicationServices.GetService<IScheduler>();
      scheduler.StartJob<HelloJob>(trigger);
    }