MdpOutboxPushJob.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132
  1. using Admin.NET.Plugin.AiDOP.DataPlatform.Executors;
  2. using Furion.Schedule;
  3. using Microsoft.Extensions.DependencyInjection;
  4. using Microsoft.Extensions.Logging;
  5. namespace Admin.NET.Plugin.AiDOP.Job;
  6. /// <summary>
  7. /// 出站 Outbox 推送作业:扫描 mdp_outbox 待推记录并调用 MdpApiPushExecutor。
  8. /// </summary>
  9. [JobDetail("job_mdp_outbox_push", Description = "MDP Outbox 出站推送", GroupName = "default", Concurrent = false)]
  10. [PeriodSeconds(60, TriggerId = "trigger_mdp_outbox_push", Description = "每 60 秒扫描 Outbox", RunOnStart = false)]
  11. public class MdpOutboxPushJob : IJob
  12. {
  13. private readonly IServiceScopeFactory _scopeFactory;
  14. private readonly ILogger _logger;
  15. public MdpOutboxPushJob(IServiceScopeFactory scopeFactory, ILoggerFactory loggerFactory)
  16. {
  17. _scopeFactory = scopeFactory;
  18. _logger = loggerFactory.CreateLogger(nameof(MdpOutboxPushJob));
  19. }
  20. public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
  21. {
  22. using var scope = _scopeFactory.CreateScope();
  23. var executor = scope.ServiceProvider.GetRequiredService<MdpApiPushExecutor>();
  24. var (success, failed, skipped) = await executor.PushPendingAsync(50, stoppingToken);
  25. if (success + failed + skipped > 0)
  26. _logger.LogInformation("[MdpOutboxPushJob] success={Success} failed={Failed} retrying={Skipped}", success, failed, skipped);
  27. }
  28. }