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 EntrustSettle.Common;
|
|
|
|
|
using EntrustSettle.Tasks;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Quartz;
|
|
|
|
|
using Quartz.Spi;
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
|
|
|
|
namespace EntrustSettle.Extensions
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 任务调度 启动服务
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class JobSetup
|
|
|
|
|
{
|
|
|
|
|
public static void AddJobSetup(this IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
if (services == null) throw new ArgumentNullException(nameof(services));
|
|
|
|
|
|
|
|
|
|
// 简易版的定时任务
|
|
|
|
|
if (AppSettings.app("TimedJob", "Enabled").ObjToBool())
|
|
|
|
|
{
|
|
|
|
|
services.AddHostedService<Job1TimedService>();
|
|
|
|
|
}
|
|
|
|
|
// Quartz版的定时任务
|
|
|
|
|
if (AppSettings.app("QuartzNetJob", "Enabled").ObjToBool())
|
|
|
|
|
{
|
|
|
|
|
services.AddSingleton<IJobFactory, JobFactory>();
|
|
|
|
|
//services.AddTransient<JobHydSubmitQuartz>(); //Job使用瞬时依赖注入
|
|
|
|
|
services.AddSingleton<ISchedulerCenter, SchedulerCenterServer>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//批量注入Quartz版的定时任务
|
|
|
|
|
var baseType = typeof(IJob);
|
|
|
|
|
var pith = AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory;
|
|
|
|
|
var assemblie = Assembly.LoadFrom(Path.Combine(pith, "EntrustSettle.Tasks.dll"));
|
|
|
|
|
var implementTypes = assemblie.GetTypes()
|
|
|
|
|
.Where(t => baseType.IsAssignableFrom(t) && t.IsClass)
|
|
|
|
|
.ToArray();
|
|
|
|
|
|
|
|
|
|
foreach (var implementType in implementTypes)
|
|
|
|
|
{
|
|
|
|
|
services.AddTransient(implementType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|