S5MdpRefreshJob.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using Furion.Schedule;
  2. using Microsoft.Extensions.DependencyInjection;
  3. using Microsoft.Extensions.Logging;
  4. using System.Text.Json;
  5. namespace Admin.NET.Plugin.AiDOP.Job;
  6. /// <summary>
  7. /// S5/S6/S7 定时入队完整重算。T8 入站硬门与共享锁由各模块 Handler / AidopT8KpiManualRefreshService 执行。
  8. /// </summary>
  9. [JobDetail("job_s5_t8_kpi_refresh",
  10. Description = "S5/S6/S7 数据重算入队(Handler 内 T8 inbound 硬门;5 次/天:02/07/12/17/22)",
  11. GroupName = "default",
  12. Concurrent = false)]
  13. [Cron("0 2,7,12,17,22 * * *",
  14. TriggerId = "trigger_s5_t8_kpi_refresh",
  15. Description = "每日 02:00/07:00/12:00/17:00/22:00 触发(5 字段:分 时 日 月 周,默认 CronStringFormat.Default)")]
  16. public class S5MdpRefreshJob : IJob
  17. {
  18. private readonly IServiceScopeFactory _scopeFactory;
  19. private readonly ILogger _logger;
  20. public S5MdpRefreshJob(IServiceScopeFactory scopeFactory, ILoggerFactory loggerFactory)
  21. {
  22. _scopeFactory = scopeFactory;
  23. _logger = loggerFactory.CreateLogger(nameof(S5MdpRefreshJob));
  24. }
  25. public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
  26. {
  27. if (!AidopJobGate.ShouldRun(nameof(S5MdpRefreshJob), _logger)) return;
  28. using var scope = _scopeFactory.CreateScope();
  29. try
  30. {
  31. foreach (var module in new[] { "S5", "S6", "S7" })
  32. {
  33. stoppingToken.ThrowIfCancellationRequested();
  34. var payload = await Admin.NET.Plugin.AiDOP.DataPlatform.MdpRebuild.ModuleRebuildJobRunner
  35. .EnqueueEnabledScopesAsync(scope.ServiceProvider, module, "AUTO", stoppingToken, _logger);
  36. _logger.LogInformation("S5MdpRefreshJob {Module} 入队 {Payload}", module, JsonSerializer.Serialize(payload));
  37. }
  38. }
  39. catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested)
  40. {
  41. _logger.LogInformation("S5MdpRefreshJob 收到停止信号,本轮结束");
  42. throw;
  43. }
  44. catch (Exception ex)
  45. {
  46. _logger.LogError(ex, "S5MdpRefreshJob 入队失败");
  47. }
  48. }
  49. }