ModuleRebuildJobRunner.cs 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. using Microsoft.Extensions.DependencyInjection;
  2. using Microsoft.Extensions.Logging;
  3. namespace Admin.NET.Plugin.AiDOP.DataPlatform.MdpRebuild;
  4. public static class ModuleRebuildJobRunner
  5. {
  6. public static async Task<(int Scopes, int Accepted, int Skipped)> EnqueueEnabledScopesAsync(
  7. IServiceProvider sp,
  8. string moduleCode,
  9. string triggerType,
  10. CancellationToken stoppingToken,
  11. ILogger logger)
  12. {
  13. var catalog = sp.GetRequiredService<MdpRebuildScopeCatalog>();
  14. var rebuild = sp.GetRequiredService<ModuleRebuildService>();
  15. var scopes = await catalog.ListEnabledScopesAsync(moduleCode, stoppingToken);
  16. var accepted = 0;
  17. var skipped = 0;
  18. foreach (var runScope in scopes)
  19. {
  20. stoppingToken.ThrowIfCancellationRequested();
  21. var (status, body) = await rebuild.EnqueueAsync(runScope.ModuleCode, runScope.TenantId, runScope.FactoryId, null, triggerType, stoppingToken);
  22. if (status == 202) accepted++;
  23. else skipped++;
  24. logger.LogInformation("Enqueue {Module} {Tenant}:{Factory} -> {Status} {Message}",
  25. runScope.ModuleCode, runScope.TenantId, runScope.FactoryId, status, body.Message);
  26. }
  27. return (scopes.Count, accepted, skipped);
  28. }
  29. }