S8TimeoutAutoEscalationJob.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using Admin.NET.Plugin.AiDOP.Service.S8;
  2. using Furion.Schedule;
  3. using Microsoft.Extensions.DependencyInjection;
  4. using Microsoft.Extensions.Logging;
  5. namespace Admin.NET.Plugin.AiDOP.Job;
  6. /// <summary>
  7. /// S8-TIMEOUT-AUTO-ESCALATION-JOB-1(P4-1):每 5 分钟扫描 sla_deadline 已超时的异常并触发 ApprovalFlow 升级。
  8. /// 实现位于 <see cref="S8TimeoutAutoEscalationService.RunOnceAsync"/>,便于管理员接口或测试复用。
  9. /// 与 <see cref="ApprovalFlow.FlowTimeoutJob"/> 同模式(IServiceScopeFactory + Furion Schedule)。
  10. /// </summary>
  11. [JobDetail("job_s8_timeout_auto_escalation",
  12. Description = "S8 超时自动升级(扫描 sla_deadline 已过期的异常并启动 EXCEPTION_ESCALATION)",
  13. GroupName = "default", Concurrent = false)]
  14. [Period(300000, TriggerId = "trigger_s8_timeout_auto_escalation", Description = "每5分钟执行")]
  15. public class S8TimeoutAutoEscalationJob : IJob
  16. {
  17. private readonly IServiceScopeFactory _scopeFactory;
  18. private readonly ILogger _logger;
  19. public S8TimeoutAutoEscalationJob(IServiceScopeFactory scopeFactory, ILoggerFactory loggerFactory)
  20. {
  21. _scopeFactory = scopeFactory;
  22. _logger = loggerFactory.CreateLogger("S8TimeoutAutoEscalationJob");
  23. }
  24. public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
  25. {
  26. using var scope = _scopeFactory.CreateScope();
  27. var svc = scope.ServiceProvider.GetRequiredService<S8TimeoutAutoEscalationService>();
  28. try
  29. {
  30. var processed = await svc.RunOnceAsync(50, stoppingToken);
  31. if (processed > 0)
  32. _logger.LogInformation("S8TimeoutAutoEscalationJob 本轮升级了 {Count} 个超时异常", processed);
  33. }
  34. catch (Exception ex)
  35. {
  36. _logger.LogError(ex, "S8TimeoutAutoEscalationJob 执行失败");
  37. }
  38. }
  39. }