| 12345678910111213141516171819202122232425262728293031323334 |
- using Admin.NET.Plugin.AiDOP.DataPlatform.UnifiedIngress;
- using Furion.Schedule;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.Logging;
- namespace Admin.NET.Plugin.AiDOP.Job;
- [JobDetail("job_mdp_raw_retention", Description = "数据中台 Raw 保留到期处置", GroupName = "default", Concurrent = false)]
- [PeriodSeconds(900, TriggerId = "trigger_mdp_raw_retention", Description = "分批清理已到期的 Raw 原文", RunOnStart = false)]
- public sealed class MdpRawRetentionJob(IServiceScopeFactory scopes, IConfiguration config, ILogger<MdpRawRetentionJob> logger) : IJob
- {
- public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
- {
- if (!AidopJobGate.ShouldRun(nameof(MdpRawRetentionJob), logger)
- || !config.GetValue<bool>("MdpRawRetention:Enabled")) return;
- using var scope = scopes.CreateScope();
- var retention = scope.ServiceProvider.GetRequiredService<MdpIngestRawRetentionService>();
- var total = 0;
- const int maxBatches = 12;
- for (var batch = 0; batch < maxBatches && !stoppingToken.IsCancellationRequested; batch++)
- {
- var count = await retention.ExpireAsync(stoppingToken);
- total += count;
- if (count < MdpIngestRawRetentionService.BatchLimit)
- break;
- }
- if (total > 0)
- logger.LogInformation("数据中台已处置 {Count} 个到期 Raw 原文,保留批次与追溯证据。", total);
- if (total == maxBatches * MdpIngestRawRetentionService.BatchLimit)
- logger.LogWarning("Raw 到期处置已达到单次上限,剩余批次由后续任务处理。");
- }
- }
|