添加项目文件。
This commit is contained in:
1 parent
05e131ca4e
commit
514d6f5255
1162 files changed
+81255
No files matched your search
@@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using HHWMS.Web.Models;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Quartz;
|
||||
using Quartz.Impl;
|
||||
using Quartz.Impl.Triggers;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Support.Quartz;
|
||||
|
||||
namespace HHWMS.Web.Support
|
||||
{
|
||||
public static class WmsServicesExtension
|
||||
{
|
||||
public static IApplicationBuilder AddQuartzJobs(this IApplicationBuilder app)
|
||||
{
|
||||
var configs = app.ApplicationServices.GetRequiredService<IOptionsMonitor<Configs>>().CurrentValue;
|
||||
var gd = app.ApplicationServices.GetRequiredService<GlobalData>();
|
||||
var dc = configs.CreateDC();
|
||||
var sp = app.ApplicationServices.GetService<IServiceProvider>();
|
||||
|
||||
Task<IScheduler> task_scheduler = StdSchedulerFactory.GetDefaultScheduler();
|
||||
var _scheduler = task_scheduler.Result;
|
||||
|
||||
var jobList = dc.Set<SysJob>().ToList();
|
||||
|
||||
foreach (var job in jobList)
|
||||
{
|
||||
new QuartzService(sp, gd, dc).AddJob(job).Wait();
|
||||
}
|
||||
|
||||
var test = gd.AllAssembly.FirstOrDefault(x => x.FullName.Contains("HHWMS.Web"));
|
||||
var t = test.GetExportedTypes().Where(x => typeof(WtmJob).IsAssignableFrom(x) && x.Name != "WtmJob");
|
||||
foreach (var item in t)
|
||||
{
|
||||
var ci = item.GetConstructor(Type.EmptyTypes);
|
||||
var job = ci?.Invoke(null) as WtmJob;
|
||||
|
||||
if (job != null)
|
||||
{
|
||||
string jobName = item.Name;
|
||||
string groupName = item.Name;
|
||||
if (_scheduler.CheckExists(new JobKey(jobName, groupName)).Result)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
JobDataMap jobDataMap = new JobDataMap();
|
||||
jobDataMap.Add("Sp", sp);
|
||||
|
||||
// 创建作业
|
||||
IJobDetail j = JobBuilder.Create(item)
|
||||
.WithIdentity(jobName, groupName)
|
||||
.UsingJobData(jobDataMap)
|
||||
.Build();
|
||||
|
||||
// 创建触发器
|
||||
ICronTrigger trigger = (ICronTrigger)TriggerBuilder.Create()
|
||||
.WithIdentity(jobName, groupName)
|
||||
.WithCronSchedule("0 0 0 1 1 ? *")
|
||||
.ForJob(new JobKey(jobName, groupName))
|
||||
.Build();
|
||||
|
||||
((CronTriggerImpl)trigger).MisfireInstruction = MisfireInstruction.CronTrigger.DoNothing;
|
||||
_scheduler.ScheduleJob(j, trigger).Wait();
|
||||
|
||||
//var builder = TriggerBuilder.Create()
|
||||
// .WithIdentity(jobName, groupName)
|
||||
// .WithCronSchedule("0 0 0 1 1 ? *")
|
||||
// .ForJob(new JobKey(jobName, groupName));
|
||||
|
||||
//var trigger = builder.Build();
|
||||
//_scheduler.ScheduleJob(j, trigger).Wait();
|
||||
|
||||
//_scheduler.PauseJob(new JobKey(jobName, groupName)).Wait();
|
||||
}
|
||||
}
|
||||
if (!_scheduler.IsStarted) _scheduler.Start().Wait();
|
||||
|
||||
return app;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user