⚡ 任务启动恢复改为异步
This commit is contained in:
parent
9170b3e999
commit
df99da04fb
@ -1,4 +1,6 @@
|
|||||||
using Quartz.Spi;
|
using Quartz.Spi;
|
||||||
|
using SqlSugar.IOC;
|
||||||
|
using ZR.Model.System;
|
||||||
using ZR.Tasks;
|
using ZR.Tasks;
|
||||||
|
|
||||||
namespace ZR.Admin.WebApi.Extensions
|
namespace ZR.Admin.WebApi.Extensions
|
||||||
@ -31,11 +33,11 @@ namespace ZR.Admin.WebApi.Extensions
|
|||||||
{
|
{
|
||||||
ITaskSchedulerServer _schedulerServer = app.ApplicationServices.GetRequiredService<ITaskSchedulerServer>();
|
ITaskSchedulerServer _schedulerServer = app.ApplicationServices.GetRequiredService<ITaskSchedulerServer>();
|
||||||
|
|
||||||
var tasks = SqlSugar.IOC.DbScoped.SugarScope.Queryable<Model.System.SysTasks>()
|
var tasks = DbScoped.SugarScope.Queryable<SysTasks>()
|
||||||
.Where(m => m.IsStart == 1).ToList();
|
.Where(m => m.IsStart == 1).ToListAsync();
|
||||||
|
|
||||||
//程序启动后注册所有定时任务
|
//程序启动后注册所有定时任务
|
||||||
foreach (var task in tasks)
|
foreach (var task in tasks.Result)
|
||||||
{
|
{
|
||||||
var result = _schedulerServer.AddTaskScheduleAsync(task);
|
var result = _schedulerServer.AddTaskScheduleAsync(task);
|
||||||
if (result.Result.Code == 200)
|
if (result.Result.Code == 200)
|
||||||
|
|||||||
@ -92,7 +92,8 @@ InternalApp.ServiceProvider = app.Services;
|
|||||||
//初始化db
|
//初始化db
|
||||||
builder.Services.AddDb(builder.Configuration, app.Environment);
|
builder.Services.AddDb(builder.Configuration, app.Environment);
|
||||||
|
|
||||||
app.UseSwagger();
|
//使用全局异常中间件
|
||||||
|
app.UseMiddleware<GlobalExceptionMiddleware>();
|
||||||
|
|
||||||
//使可以多次多去body内容
|
//使可以多次多去body内容
|
||||||
app.Use((context, next) =>
|
app.Use((context, next) =>
|
||||||
@ -118,8 +119,8 @@ app.UseAuthorization();
|
|||||||
app.UseResponseCaching();
|
app.UseResponseCaching();
|
||||||
//恢复/启动任务
|
//恢复/启动任务
|
||||||
app.UseAddTaskSchedulers();
|
app.UseAddTaskSchedulers();
|
||||||
//使用全局异常中间件
|
//使用swagger
|
||||||
app.UseMiddleware<GlobalExceptionMiddleware>();
|
app.UseSwagger();
|
||||||
//启用客户端IP限制速率
|
//启用客户端IP限制速率
|
||||||
app.UseIpRateLimiting();
|
app.UseIpRateLimiting();
|
||||||
app.UseRateLimiter();
|
app.UseRateLimiter();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user