Files
kunshan-bzfm-mes-backend/DOAN.Tasks/TaskScheduler/Job_Device_Execute.cs
2024-12-21 10:02:13 +08:00

55 lines
2.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
using DOAN.Service.MES.dev;
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);
}
}
}