feat(dal, TemplateDistributorWorker): NextRunServiceV2 - реализован метод распределения шаблонов. Обновлен TemplateDistributorWorker для использования новой логики.

This commit is contained in:
Mikhail Trubnikov
2026-02-13 15:39:21 +10:00
parent 858dd8c31c
commit 89b6cdf731
7 changed files with 234 additions and 46 deletions

View File

@@ -11,13 +11,15 @@ namespace PARR.TemplateDistributor
internal class TemplateDistributor : ITemplateDistributor
{
private readonly ILogger<TemplateDistributor> logger;
private readonly INextRunService nextRunService;
//private readonly INextRunService nextRunService;
private readonly INextRunServiceV2 nextRunService;
private readonly ITemplateService templateService;
private readonly IRobotConfigurationService robotConfigurationService;
public TemplateDistributor(
ILogger<TemplateDistributor> logger,
INextRunService nextRunService,
//INextRunService nextRunService,
INextRunServiceV2 nextRunService,
ITemplateService templateService,
IRobotConfigurationService robotConfigurationService
)
@@ -32,20 +34,22 @@ namespace PARR.TemplateDistributor
public async Task DistributeAsync(TemplateDistributorMq mqResponse)
{
var jobGroupId = mqResponse.JobGroupId;
// распределяем шаблоны только в статусе Used
var templateStatusType = TemplateStatusTypeEnum.Used;
// вызвать метод распределения, и получить новые даты
var distributedTemplates = await nextRunService.GetNextRunForJobGroupWithAutoDistributionAsync(jobGroupId);
var distributedTemplates = await nextRunService.GetNextRunForJobGroupWithAutoDistributionAsync(jobGroupId, templateStatusType);
if (distributedTemplates == null)
{
logger.LogWarning("При распределении шаблонов по jobGroupId {jobGroupId} вернулся null. Это ошибка. Прекращаю распределение.", jobGroupId);
logger.LogError("При распределении шаблонов по jobGroupId {jobGroupId} вернулся null. Это ошибка. Прекращаю распределение.", jobGroupId);
return;
}
// получить список шаблонов, сравнить их с распределенными, обновить даты, сохранить
var groupTemplates = await templateService.Get()
.Include(t => t.RobotConfigurations)
.Where(t => t.Job.GroupId == jobGroupId)
.Where(t => t.Job!.GroupId == jobGroupId && t.StatusTypeId == templateStatusType)
.ToListAsync();
if (!groupTemplates.Any())