using Quartz;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace IStation.Server
|
{
|
/// <summary>
|
/// 自定义实时任务
|
/// </summary>
|
public class CustomRealJob : Quartz.IJob
|
{
|
internal const string Instance = "Instance";
|
|
/// <summary>
|
///
|
/// </summary>
|
public Task Execute(IJobExecutionContext context)
|
{
|
return Task.Run(() =>
|
{
|
try
|
{
|
var dataMap = context.MergedJobDataMap;
|
var jobModel = (Model.CustomRealJob)dataMap[Instance];
|
if (jobModel == null)
|
return;
|
var jobExecuter = JobFactory.CreateJob(jobModel.Execution);
|
if (jobExecuter == null)
|
{
|
LogHelper.Error($"自定义实时任务,ID:{jobModel.ID},NO:{jobModel.NO},Name:{jobModel.Name},Execution:{jobModel.Execution},创建任务对象失败!");
|
return;
|
}
|
jobExecuter.Execute();
|
}
|
catch (Exception ex)
|
{
|
LogHelper.Error("自定义实时任务,执行出错", ex);
|
var e = new JobExecutionException(ex);
|
throw e;
|
}
|
|
});
|
}
|
|
|
}
|
}
|