1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- using log4net;
- using Microsoft.AspNetCore.Builder;
- using Ropin.Inspection.Common.Helper;
- using Ropin.Inspection.Service.Interface;
- using Ropin.Inspection.Tasks.QuartzNet;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Ropin.Core.Extensions.Middlewares
- {
- /// <summary>
- /// Quartz 启动服务
- /// </summary>
- public static class QuartzJobMildd
- {
- private static readonly ILog log = LogManager.GetLogger(typeof(QuartzJobMildd));
- public static void UseQuartzJobMildd(this IApplicationBuilder app, ITasksQzServices tasksQzServices, ISchedulerCenter schedulerCenter)
- {
- if (app == null) throw new ArgumentNullException(nameof(app));
- try
- {
- if (Appsettings.app("Middleware", "QuartzNetJob", "Enabled").ObjToBool())
- {
- var allQzServices = tasksQzServices.GetAllAsync().Result;//.Query().Result;
- if (allQzServices == null || !allQzServices.Any())
- {
- return;
- }
- foreach (var item in allQzServices)
- {
- if (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;
- }
- }
- }
- }
|