You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using Admin.Core.Common;
|
|
|
|
|
using Admin.Core.IService.ISys;
|
|
|
|
|
using Admin.Core.Tasks;
|
|
|
|
|
using log4net;
|
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace Admin.Core.Extensions
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Quartz 启动服务
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class QuartzJobMildd
|
|
|
|
|
{
|
|
|
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(QuartzJobMildd));
|
|
|
|
|
public static void UseQuartzJobMildd(this IApplicationBuilder app, ISysTasksQzService tasksQzService, ISchedulerCenter schedulerCenter)
|
|
|
|
|
{
|
|
|
|
|
if (app == null) throw new ArgumentNullException(nameof(app));
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (Appsettings.app("Middleware", "QuartzNetJob", "Enabled").ObjToBool())
|
|
|
|
|
{
|
|
|
|
|
//**注意在此处查询《wpf异步查询不到改为同步》**
|
|
|
|
|
var allQzServices =tasksQzService.Query(x => x.DelFlag == false);
|
|
|
|
|
foreach (var item in allQzServices)
|
|
|
|
|
{
|
|
|
|
|
if ((bool)item.IsStart)
|
|
|
|
|
{
|
|
|
|
|
var ResuleModel = schedulerCenter.AddScheduleJobAsync(item).Result;
|
|
|
|
|
if (ResuleModel.success)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"QuartzNetJob{item.Name}启动成功!");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"QuartzNetJob{item.Name}启动失败!错误信息:{ResuleModel.msg}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
log.Error($"An error was reported when starting the job service.\n{e.Message}");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|