|
@@ -1,4 +1,7 @@
|
|
|
+using Quartz;
|
|
|
+using Quartz.AspNetCore;
|
|
|
using Scheduler.Components;
|
|
|
+using Scheduler.ScheduleModule;
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
@@ -7,6 +10,43 @@ builder.Services.AddRazorComponents()
|
|
|
.AddInteractiveServerComponents()
|
|
|
.AddInteractiveWebAssemblyComponents();
|
|
|
|
|
|
+var services = builder.Services;
|
|
|
+services.AddHttpClient();
|
|
|
+services.AddSingleton<BaseHttpRequestJob>();
|
|
|
+
|
|
|
+var jobs = builder.Configuration.GetSection("Jobs")?.Get<List<AppJob>>()?
|
|
|
+ .Where(d => d.Enable && !string.IsNullOrEmpty(d.Cron))
|
|
|
+ .ToList();
|
|
|
+if (jobs != null && jobs.Any())
|
|
|
+{
|
|
|
+ builder.Services.AddQuartz(d =>
|
|
|
+ {
|
|
|
+ d.SchedulerId = "default_scheduler";
|
|
|
+ d.InterruptJobsOnShutdown = true;
|
|
|
+ d.InterruptJobsOnShutdownWithWait = true;
|
|
|
+ d.MaxBatchSize = 3;
|
|
|
+
|
|
|
+ d.AddJob<BaseHttpRequestJob>(BaseHttpRequestJob.Key);
|
|
|
+ foreach (var job in jobs)
|
|
|
+ {
|
|
|
+ d.AddTrigger(t => t
|
|
|
+ .UsingJobData("job", System.Text.Json.JsonSerializer.Serialize(job))
|
|
|
+ .ForJob(BaseHttpRequestJob.Key)
|
|
|
+ .StartNow()
|
|
|
+ .WithCronSchedule(job.Cron));
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ builder.Services.AddQuartzServer(d =>
|
|
|
+ {
|
|
|
+ d.WaitForJobsToComplete = true;
|
|
|
+ d.StartDelay = TimeSpan.FromSeconds(5);
|
|
|
+ });
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
var app = builder.Build();
|
|
|
|
|
|
// Configure the HTTP request pipeline.
|