去掉hangfire 增加quartZ 方便部署,免得需要两个数据库

This commit is contained in:
2023-06-27 17:04:14 +08:00
parent 4eb5c97725
commit 91a6f20dba
5 changed files with 89 additions and 38 deletions
+2
View File
@@ -86,6 +86,8 @@
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="6.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.10" />
<PackageReference Include="Quartz.Extensions.DependencyInjection" Version="3.6.2" />
<PackageReference Include="Quartz.Extensions.Hosting" Version="3.6.2" />
<PackageReference Include="Serilog.AspNetCore" Version="6.0.1" />
<PackageReference Include="Serilog.Enrichers.ClientInfo" Version="1.2.0" />
<PackageReference Include="Serilog.Sinks.Email" Version="2.4.0" />
+2 -2
View File
@@ -114,7 +114,7 @@ namespace IRaCIS.Core.API
//services.AddDistributedMemoryCache();
// hangfire 定时任务框架 有界面,更友好~
services.AddhangfireSetup(_configuration);
//services.AddhangfireSetup(_configuration);
// QuartZ 定时任务框架 使用了hangfire 暂时不用,后续需要可以打开,已经配好
services.AddQuartZSetup(_configuration);
@@ -181,7 +181,7 @@ namespace IRaCIS.Core.API
app.UseLogDashboard("/LogDashboard");
//hangfire
app.UseHangfireConfig(env);
//app.UseHangfireConfig(env);
////暂时废弃
//app.UseHttpReports();
@@ -1,6 +1,8 @@
using IRaCIS.Application.Services.BackGroundJob;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Quartz;
namespace IRaCIS.Core.API
{
@@ -8,37 +10,35 @@ namespace IRaCIS.Core.API
{
public static void AddQuartZSetup(this IServiceCollection services, IConfiguration configuration)
{
//services.AddTransient<CacheTrialStatusQuartZJob>();
services.AddTransient<CacheTrialStatusQuartZJob>();
//services.AddQuartz(q =>
//{
// // base quartz scheduler, job and trigger configuration
services.AddQuartz(q =>
{
// base quartz scheduler, job and trigger configuration
// // as of 3.3.2 this also injects scoped services (like EF DbContext) without problems
// q.UseMicrosoftDependencyInjectionJobFactory();
// as of 3.3.2 this also injects scoped services (like EF DbContext) without problems
q.UseMicrosoftDependencyInjectionJobFactory();
// // 基本Quartz调度器、作业和触发器配置
// var jobKey = new JobKey("RegularTrialWork", "regularWorkGroup");
// q.AddJob<CacheTrialStatusQuartZJob>(jobKey, j => j
// .WithDescription("Trial regular work")
// );
// q.AddTrigger(t => t
// .WithIdentity("TrialStatusTrigger")
// .ForJob(jobKey)
// //.StartNow()
// //.WithSimpleSchedule(x => x.WithInterval(TimeSpan.FromSeconds(15))//开始秒数 15s
// // .RepeatForever())//持续工作
// .WithCronSchedule("0 0 0/2 * * ?")//每小时执行一次
// .WithDescription("My regular trial work trigger")
// );
//});
// 基本Quartz调度器、作业和触发器配置
var jobKey = new JobKey("RegularTrialWork", "regularWorkGroup");
q.AddJob<CacheTrialStatusQuartZJob>(jobKey, j => j
.WithDescription("Trial regular work")
);
q.AddTrigger(t => t
.WithIdentity("TrialStatusTrigger")
.ForJob(jobKey)
.WithCronSchedule("0 0 * * * ?")
.WithDescription("My regular trial work trigger")
);
});
//// ASP.NET Core hosting
//services.AddQuartzServer(options =>
//{
// // when shutting down we want jobs to complete gracefully
// options.WaitForJobsToComplete = true;
//});
// ASP.NET Core hosting
services.AddQuartzHostedService(options =>
{
// when shutting down we want jobs to complete gracefully
options.WaitForJobsToComplete = true;
});
}
}