using Quartz; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IStation.Server { /// /// 单个任务 /// [DisallowConcurrentExecution]//此特性标识 必须等待这次任务执行完成后,才能执行下次任务 internal class SingleJob : IJob { public const string ConfigureTagName = "Configure"; public Task Execute(IJobExecutionContext context) { return Task.Run(() => { //获取MiddleLib配置 var dataMap = context.MergedJobDataMap; var configure = (Model.DataDockingConfigureExMiddleLib)dataMap[ConfigureTagName]; if (configure == null) return; try { if (configure.Mappers == null || configure.Mappers.Count < 1) { LogHelper.Info($"中间库数据对接中:{configure.Name},未配置映射关系!"); return; } //创建对接对象 var dataDocking = DataDockingMiddleLibFactory.CreateMiddleLib(configure.ConfigureParas.DependencyFile); if (dataDocking == null) { LogHelper.Info($"中间库数据对接中:{configure.Name} ,创建对接对象失败!"); return; } dataDocking.HandleData(configure.Mappers, (receive_list) => { if (receive_list == null || receive_list.Count < 1) { LogHelper.Info($"中间库数据对接中:{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($"中间库数据对接中:{configure.Name},成功推入通道{receive_list.Count}条数据!"); }); } catch (Exception ex) { LogHelper.Error($"中间数据库对接,任务执行出错,配置名称:{configure.Name}!", ex); var e = new JobExecutionException(ex); throw e; } }); } } }