using Quartz;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
namespace IStation.Server
|
{
|
/// <summary>
|
/// 单个任务
|
/// </summary>
|
[DisallowConcurrentExecution]//此特性标识 必须等待这次任务执行完成后,才能执行下次任务
|
internal class SingleJob : IJob
|
{
|
public const string ConfigureTagName = "Configure";
|
|
public Task Execute(IJobExecutionContext context)
|
{
|
|
return Task.Run(() =>
|
{
|
|
//获取配置
|
var dataMap = context.MergedJobDataMap;
|
var configure = (Model.DataDockingConfigureExApi)dataMap[ConfigureTagName];
|
if (configure == null)
|
return;
|
try
|
{
|
//映射关系
|
if (configure.Mappers == null || configure.Mappers.Count < 1)
|
{
|
LogHelper.Info($"Api数据对接任务中:{configure.Name},未进行映射关系配置!");
|
return;
|
}
|
|
//创建数据对接对象
|
var dataDocking = DataDockingApiFactory.CreateApi<IDataDockingApi.IHandleHelper>(configure.ConfigureParas.DependencyFile);
|
if (dataDocking == null)
|
{
|
LogHelper.Info($"Api数据对接任务中,{configure.Name},创建数据对接对象失败!!");
|
return;
|
}
|
|
dataDocking.HandleData(configure.Mappers, (receive_list) =>
|
{
|
if (receive_list == null || receive_list.Count < 1)
|
{
|
LogHelper.Info($"Api数据对接任务中,{configure.Name},接收数据为空!");
|
return;
|
}
|
|
var queue = new RabbitMqQueueHelper();
|
queue.Push(ConfigHelper.QueueName, new Model.MonitorDataDockingCorpRecord() { CorpID = configure.CorpID, ConfigureID = configure.ID, Records = receive_list });
|
|
LogHelper.Info($"api配置名称:{configure.Name},成功推入通道{receive_list.Count}条数据!");
|
});
|
}
|
catch (Exception ex)
|
{
|
LogHelper.Error($"Api数据对接,任务执行出错,配置名称:{configure.Name}", ex);
|
var e = new JobExecutionException(ex);
|
throw e;
|
}
|
});
|
|
}
|
|
|
|
}
|
}
|