-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
51 lines (47 loc) · 2.08 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Quartz;
using Shortener.Service.Jobs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Shortener.Service.Extension;
namespace Shortener.Service
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
// Add selfhost port for demo
webBuilder.UseUrls("http://localhost:8000");
})
.ConfigureServices((hostContext, services) =>
{
services.AddQuartz(q =>
{
q.UseMicrosoftDependencyInjectionScopedJobFactory();
// Add periodical/scheduled jobs
// Time definition is in appsettings
// https://www.quartz-scheduler.net/documentation/quartz-3.x/tutorial/crontriggers.html
// Daily - MON-SUN on 08:00 CET for the previous day => Cron expression: "0 0 8 ? * MON-SUN"
q.AddJobAndTrigger<SendDailyNotification>(hostContext.Configuration);
// Weekly - MON on 08:01 CET for the past week => Cron expression: "0 1 8 ? * MON"
q.AddJobAndTrigger<SendWeeklyNotification>(hostContext.Configuration);
// Monthly - first MON on the month for the past month => Cron expression: "0 2 8 * * MON#1"
q.AddJobAndTrigger<SendMonthlyNotification>(hostContext.Configuration);
});
services.AddQuartzHostedService(
q => q.WaitForJobsToComplete = true);
});
}
}