using Microsoft.AspNetCore.Builder; using System; using System.Collections.Generic; using System.Text; using WIDESEA.QuartzJob; using WIDESEA_Core; using WIDESEA_Core.Helper; namespace WIDESEA_StorageTaskServices { /// /// Quartz 启动服务 /// public static class QuartzJobMiddleWare { public static void UseQuartzJobMildd(this IApplicationBuilder app) { if (app == null) throw new ArgumentNullException(nameof(app)); var schedulerCenter = app.ApplicationServices.GetService(typeof(ISchedulerCenter)) as ISchedulerCenter; try { var allQzServices = new List() { new TasksQz() { Id = 1, AssemblyName = "WIDESEA_StorageTaskServices", ClassName = "BackgroundJob", CreateTime = DateTime.Now, IntervalSecond = 10, IsDeleted = false, IsStart = false, JobGroup = "WIDESEA_StorageTaskServices", Name = "BackgroundJob", TriggerType = 0 }, new TasksQz() { Id = 2, AssemblyName = "WIDESEA_StorageTaskServices", ClassName = "WhiteCarAutoOutJob", CreateTime = DateTime.Now, IntervalSecond = 60, IsDeleted = false, IsStart = false, JobGroup = "AutoTask", Name = "AutoTask", TriggerType = 0 } }; //if(App.HostEnvironment.IsDevelopment()) //{ // return; //} foreach (var item in allQzServices) { var ResuleModel = schedulerCenter.AddScheduleJobAsync(item).Result; if (ResuleModel.Status) { ConsoleHelper.WriteSuccessLine($"{item.ClassName}启动成功"); } else { Console.Out.WriteLine($"QuartzNetJob{item.Name}启动失败!错误信息:{ResuleModel.Message}"); } } schedulerCenter.StartScheduleAsync(); } catch (Exception e) { throw; } } } }