S5MdpRefreshJob.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. using var scope = _scopeFactory.CreateScope();
  28. try
  29. {
  30. foreach (var module in new[] { "S5", "S6", "S7" })
  31. {
  32. stoppingToken.ThrowIfCancellationRequested();
  33. var payload = await Admin.NET.Plugin.AiDOP.DataPlatform.MdpRebuild.ModuleRebuildJobRunner
  34. .EnqueueEnabledScopesAsync(scope.ServiceProvider, module, "AUTO", stoppingToken, _logger);
  35. _logger.LogInformation("S5MdpRefreshJob {Module} 入队 {Payload}", module, JsonSerializer.Serialize(payload));
  36. }
  37. }
  38. catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested)
  39. {
  40. _logger.LogInformation("S5MdpRefreshJob 收到停止信号,本轮结束");
  41. throw;
  42. }
  43. catch (Exception ex)
  44. {
  45. _logger.LogError(ex, "S5MdpRefreshJob 入队失败");
  46. }
  47. }
  48. }