using Admin.NET.Plugin.AiDOP.Service.S8;
using Furion.Schedule;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace Admin.NET.Plugin.AiDOP.Job;
///
/// S8-TIMEOUT-AUTO-ESCALATION-JOB-1(P4-1):每 5 分钟扫描 sla_deadline 已超时的异常并触发 ApprovalFlow 升级。
/// 实现位于 ,便于管理员接口或测试复用。
/// 与 同模式(IServiceScopeFactory + Furion Schedule)。
///
[JobDetail("job_s8_timeout_auto_escalation",
Description = "S8 超时自动升级(扫描 sla_deadline 已过期的异常并启动 EXCEPTION_ESCALATION)",
GroupName = "default", Concurrent = false)]
[Period(300000, TriggerId = "trigger_s8_timeout_auto_escalation", Description = "每5分钟执行")]
public class S8TimeoutAutoEscalationJob : IJob
{
private readonly IServiceScopeFactory _scopeFactory;
private readonly ILogger _logger;
public S8TimeoutAutoEscalationJob(IServiceScopeFactory scopeFactory, ILoggerFactory loggerFactory)
{
_scopeFactory = scopeFactory;
_logger = loggerFactory.CreateLogger("S8TimeoutAutoEscalationJob");
}
public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
{
using var scope = _scopeFactory.CreateScope();
var svc = scope.ServiceProvider.GetRequiredService();
try
{
var processed = await svc.RunOnceAsync(50, stoppingToken);
if (processed > 0)
_logger.LogInformation("S8TimeoutAutoEscalationJob 本轮升级了 {Count} 个超时异常", processed);
}
catch (Exception ex)
{
_logger.LogError(ex, "S8TimeoutAutoEscalationJob 执行失败");
}
}
}