using Furion.Schedule; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using System.Text.Json; using Admin.NET.Plugin.AiDOP.DataPlatform.MdpRebuild; namespace Admin.NET.Plugin.AiDOP.Job; /// /// S1–S7 夜间串行全量兜底。triggerType 用 , /// 穿透 AUTO 冷却窗口;串行靠 GlobalMaxParallelScopes = 1,本 Job 一次性入队全部 scope。 /// [JobDetail("job_mdp_nightly_full_rebuild", Description = "S1–S7 夜间串行全量兜底(穿透 AUTO 冷却窗口)", GroupName = "default", Concurrent = false)] [Cron("40 3 * * *", TriggerId = "trigger_mdp_nightly_full_rebuild", Description = "每日 03:40 触发(5 字段:分 时 日 月 周)")] public class MdpNightlyFullRebuildJob : IJob { private static readonly string[] Modules = ["S1", "S2", "S3", "S4", "S5", "S6", "S7"]; private readonly IServiceScopeFactory _scopeFactory; private readonly ILogger _logger; public MdpNightlyFullRebuildJob(IServiceScopeFactory scopeFactory, ILoggerFactory loggerFactory) { _scopeFactory = scopeFactory; _logger = loggerFactory.CreateLogger(nameof(MdpNightlyFullRebuildJob)); } public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken) { if (!AidopJobGate.ShouldRun(nameof(MdpNightlyFullRebuildJob), _logger)) return; using var scope = _scopeFactory.CreateScope(); try { foreach (var module in Modules) { stoppingToken.ThrowIfCancellationRequested(); var payload = await ModuleRebuildJobRunner.EnqueueEnabledScopesAsync( scope.ServiceProvider, module, ModuleRebuildTriggerType.AutoNightly, stoppingToken, _logger); _logger.LogInformation("MdpNightlyFullRebuildJob {Module} 入队 {Payload}", module, JsonSerializer.Serialize(payload)); } } catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested) { _logger.LogInformation("MdpNightlyFullRebuildJob 收到停止信号,本轮结束"); throw; } catch (Exception ex) { _logger.LogError(ex, "MdpNightlyFullRebuildJob 入队失败"); } } }