54 lines
2.0 KiB
C#
54 lines
2.0 KiB
C#
using Infrastructure;
|
||
using Infrastructure.Attribute;
|
||
using Microsoft.Extensions.DependencyInjection;
|
||
using Quartz;
|
||
using Quartz.Impl.Triggers;
|
||
using Quartz.Impl;
|
||
using SqlSugar.IOC;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using DOAN.Model.System;
|
||
using DOAN.Model.MES.dev;
|
||
using DOAN.Model.MES.dev.Dto;
|
||
using DOAN.Service.MES.dev.IService;
|
||
|
||
namespace DOAN.Tasks.TaskScheduler
|
||
{
|
||
/// <summary>
|
||
/// 设备管理 调度每日的巡检
|
||
/// </summary>
|
||
[AppService(ServiceType = typeof(Job_Device_Execute), ServiceLifetime = LifeTime.Scoped)]
|
||
public class Job_Device_Execute : JobBase, IJob
|
||
{
|
||
private readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||
|
||
private IDeviceTaskExecuteService deviceTaskExecute;
|
||
public Job_Device_Execute(IDeviceTaskExecuteService deviceTaskExecute)
|
||
{
|
||
this.deviceTaskExecute = deviceTaskExecute;
|
||
}
|
||
public async Task Execute(IJobExecutionContext context)
|
||
{
|
||
await ExecuteJob(context, async () => await Run(context));
|
||
}
|
||
public async Task Run(IJobExecutionContext context)
|
||
{
|
||
AbstractTrigger trigger = (context as JobExecutionContextImpl).Trigger as AbstractTrigger;
|
||
//var info = await tasksQzService.CopyNew().GetByIdAsync(trigger.JobName);
|
||
// CopyNew 在多线程环境中,为每个线程或任务创建新的 SugarScope 实例以避免线程安全问题
|
||
var info = await DbScoped.SugarScope.CopyNew().Queryable<SysTasks>().FirstAsync(f => f.ID == trigger.JobName);
|
||
if (info == null)
|
||
{
|
||
throw new CustomException($"任务{trigger?.JobName}设备管理调度请求执行失败,任务不存在");
|
||
}
|
||
|
||
int result = deviceTaskExecute.ScanEveryTask();
|
||
logger.Info($"(job)任务【{info.Name}】设备管理调度请求执行结果=" + result);
|
||
|
||
}
|
||
}
|
||
}
|