去掉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
@@ -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;
});
}
}