Skip to content

Commit d7cca03

Browse files
authored
Merge pull request #642 from poppastring/updated-scheduler
Updated scheduling to use Coravel
2 parents 3865b0b + 065a929 commit d7cca03

File tree

4 files changed

+20
-47
lines changed

4 files changed

+20
-47
lines changed

source/DasBlog.Services/DasBlog.Services.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
<ProjectReference Include="..\DasBlog.Web.Core\DasBlog.Core.csproj" />
1313
</ItemGroup>
1414
<ItemGroup>
15+
<PackageReference Include="Coravel" Version="4.1.2" />
1516
<PackageReference Include="Kveer.XmlRPC" Version="1.2.0" />
1617
<PackageReference Include="MailKit" Version="2.15.0" />
1718
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
1819
<PackageReference Include="Quartz.AspNetCore" Version="3.3.3" />
19-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All"/>
20+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
2021
</ItemGroup>
2122
<ItemGroup>
2223
<FrameworkReference Include="Microsoft.AspNetCore.App" />

source/DasBlog.Services/Scheduler/SiteReport.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
using System.Net.Mail;
55
using System.Text;
66
using System.Threading.Tasks;
7+
using Coravel.Invocable;
78
using DasBlog.Services.ActivityLogs;
89
using Microsoft.Extensions.Logging;
910
using newtelligence.DasBlog.Runtime;
10-
using Quartz;
1111

1212
namespace DasBlog.Services.Scheduler
1313
{
14-
public class SiteEmailReport : IJob
14+
public class SiteEmailReport : IInvocable
1515
{
1616
private readonly ILogger<SiteEmailReport> logger;
1717
private readonly IActivityService activityService;
@@ -34,11 +34,11 @@ public SiteEmailReport(ILogger<SiteEmailReport> logger, IActivityService activit
3434
EMAIL_TITLE = string.Format("Weblog Daily Activity Report for {0}, {1}", midnight.DayOfWeek, midnight.ToString("MMMM dd, yyyy"));
3535
}
3636

37-
public async Task Execute(IJobExecutionContext context)
37+
public async Task Invoke()
3838
{
3939
if(dasBlogSettings.SiteConfiguration.EnableDailyReportEmail)
4040
{
41-
logger.LogInformation(context.JobDetail.Key + " job executing, triggered by " + context.Trigger.Key);
41+
logger.LogInformation("Daily email report triggered");
4242

4343
var emailbody = FormatEmail();
4444

source/DasBlog.Web.UI/DasBlog.Web.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
</PropertyGroup>
2323
<ItemGroup>
2424
<PackageReference Include="AutoMapper" Version="10.1.1" />
25+
<PackageReference Include="Coravel" Version="4.1.2" />
2526
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.19.0" />
2627
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.0" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.Extensions" Version="6.0.0" />
2728
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.0" />
@@ -31,7 +32,7 @@
3132
<PackageReference Include="NWebsec.AspNetCore.Middleware" Version="3.0.0" />
3233
<PackageReference Include="reCAPTCHA.AspNetCore" Version="3.0.10" />
3334
<PackageReference Include="Quartz.AspNetCore" Version="3.3.3" />
34-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All"/>
35+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
3536
</ItemGroup>
3637
<ItemGroup>
3738
<ProjectReference Include="..\DasBlog.CLI\DasBlog.CLI.csproj" />

source/DasBlog.Web.UI/Startup.cs

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using AutoMapper;
2+
using Coravel;
23
using DasBlog.Core.Common;
34
using DasBlog.Managers;
45
using DasBlog.Managers.Interfaces;
@@ -29,7 +30,6 @@
2930
using Microsoft.Extensions.FileProviders;
3031
using Microsoft.Extensions.Hosting;
3132
using Microsoft.Extensions.Logging;
32-
using Quartz;
3333
using System;
3434
using System.IO;
3535
using System.Linq;
@@ -178,6 +178,9 @@ public void ConfigureServices(IServiceCollection services)
178178
services
179179
.AddHttpContextAccessor();
180180

181+
services.AddScheduler();
182+
services.AddTransient<SiteEmailReport>();
183+
181184
services
182185
.AddTransient<IDasBlogSettings, DasBlogSettings>()
183186
.AddTransient<IUserStore<DasBlogUser>, DasBlogUserStore>()
@@ -237,46 +240,6 @@ public void ConfigureServices(IServiceCollection services)
237240
options.CheckConsentNeeded = context => flag;
238241
options.MinimumSameSitePolicy = SameSiteMode.None;
239242
});
240-
241-
services.AddQuartz(q =>
242-
{
243-
q.SchedulerId = "Scheduler-Core";
244-
245-
q.UseMicrosoftDependencyInjectionJobFactory(options =>
246-
{
247-
// if we don't have the job in DI, allow fallback to configure via default constructor
248-
options.AllowDefaultConstructor = true;
249-
});
250-
251-
q.UseSimpleTypeLoader();
252-
q.UseInMemoryStore();
253-
q.UseDefaultThreadPool(tp =>
254-
{
255-
tp.MaxConcurrency = 10;
256-
});
257-
258-
var jobKey = new JobKey("key1", "main-group");
259-
260-
q.AddJob<SiteEmailReport>(j => j
261-
.StoreDurably()
262-
.WithIdentity(jobKey)
263-
.WithDescription("Site report job")
264-
);
265-
266-
q.AddTrigger(t => t
267-
.WithIdentity("Simple Trigger")
268-
.ForJob(jobKey)
269-
.StartNow()
270-
.WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(23, 45))
271-
.WithDescription("my awesome simple trigger")
272-
273-
);
274-
});
275-
276-
services.AddQuartzServer(options =>
277-
{
278-
options.WaitForJobsToComplete = true;
279-
});
280243
}
281244

282245
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -299,6 +262,14 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IDasBlog
299262
app.UseHsts(options => options.MaxAge(days: 30));
300263
}
301264

265+
app.ApplicationServices.UseScheduler(scheduler =>
266+
{
267+
scheduler
268+
.Schedule<SiteEmailReport>()
269+
.DailyAt(23, 19)
270+
.Zoned(TimeZoneInfo.Local);
271+
});
272+
302273
if (!siteOk)
303274
{
304275
app.Run(async context => await context.Response.WriteAsync(siteError));

0 commit comments

Comments
 (0)