You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.9 KiB
59 lines
1.9 KiB
using System;
|
|
using zzz.Common;
|
|
using zzz.Model.Entity;
|
|
using zzz.Repository;
|
|
using zzz.Services.Sys.TasksQzs;
|
|
using zzz.Tasks;
|
|
using log4net;
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
namespace zzz.Extensions.Middlewares
|
|
{
|
|
/// <summary>
|
|
/// Quartz 启动服务
|
|
/// </summary>
|
|
public static class QuartzJobMiddleware
|
|
{
|
|
private static readonly ILog Log = LogManager.GetLogger(typeof(QuartzJobMiddleware));
|
|
public static async void UseQuartzJobMiddleware(
|
|
this IApplicationBuilder app,
|
|
//ITasksQzServices tasksQzServices,
|
|
IBaseRepository<TasksQz> tasksrep,
|
|
ISchedulerCenter schedulerCenter
|
|
)
|
|
{
|
|
if (app == null) throw new ArgumentNullException(nameof(app));
|
|
|
|
try
|
|
{
|
|
if (Appsettings.app("Middleware", "QuartzNetJob").ObjToBool())
|
|
{
|
|
|
|
var allQzServices = await tasksrep.QueryAsync();
|
|
foreach (var item in allQzServices)
|
|
{
|
|
if (item.IsStart)
|
|
{
|
|
var result = schedulerCenter.AddScheduleJobAsync(item).Result;
|
|
if (result.success)
|
|
{
|
|
Console.WriteLine($"QuartzNetJob{item.Name}启动成功!");
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine($"QuartzNetJob{item.Name}启动失败!错误信息:{result.message}");
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error($"An error was reported when starting the job service.\n{e.Message}");
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|