| | | 1 | | using Quartz; |
| | | 2 | | using Estud.Back.Webhooks; |
| | | 3 | | |
| | | 4 | | namespace Estud.Back.Configs; |
| | | 5 | | |
| | | 6 | | public static class QuartzConfigs |
| | | 7 | | { |
| | | 8 | | public static void AddQuartzConfigs(this WebApplicationBuilder builder) |
| | | 9 | | { |
| | 2 | 10 | | var commands = builder.Configuration.Jobs.CommandsPollingIntervalInSeconds; |
| | 2 | 11 | | var webhookCalls = builder.Configuration.Jobs.WebhookCallsPollingIntervalInSeconds; |
| | | 12 | | |
| | 2 | 13 | | builder.Services.AddQuartz(q => |
| | 2 | 14 | | { |
| | 2 | 15 | | var commandsId = nameof(CommandsProcessor); |
| | 4 | 16 | | q.AddJob<CommandsProcessor>(j => j.WithIdentity(commandsId)); |
| | 4 | 17 | | q.AddTrigger(t => t |
| | 4 | 18 | | .ForJob(commandsId) |
| | 4 | 19 | | .WithIdentity($"{commandsId}-trigger") |
| | 4 | 20 | | .WithSimpleSchedule(s => s.WithIntervalInSeconds(commands).RepeatForever()) |
| | 2 | 21 | | ); |
| | 2 | 22 | | |
| | 2 | 23 | | var webhookCallsId = nameof(PendingWebhookCallsProcessor); |
| | 4 | 24 | | q.AddJob<PendingWebhookCallsProcessor>(j => j.WithIdentity(webhookCallsId)); |
| | 4 | 25 | | q.AddTrigger(t => t |
| | 4 | 26 | | .ForJob(webhookCallsId) |
| | 4 | 27 | | .WithIdentity($"{webhookCallsId}-trigger") |
| | 4 | 28 | | .WithSimpleSchedule(s => s.WithIntervalInSeconds(webhookCalls).RepeatForever()) |
| | 2 | 29 | | ); |
| | 4 | 30 | | }); |
| | | 31 | | |
| | 4 | 32 | | builder.Services.AddQuartzHostedService(q => q.WaitForJobsToComplete = true); |
| | 2 | 33 | | } |
| | | 34 | | } |