feat(api,core): Задания роботам на обновление расписаний, выдается с периодом охлаждения, если последнее изменение было NextRunWorker или EsppScheduleWorker и значение lastRun+ период охлаждения, меньше чем сейчас.

This commit is contained in:
Mikhail Trubnikov
2026-07-10 14:11:16 +10:00
parent 33cdc29e80
commit 33b0576ccc
8 changed files with 79 additions and 467 deletions

View File

@@ -61,69 +61,5 @@ namespace PARR.NextRun
}, workerSettings.RepeatEvery);
}
///// <summary>
///// Рассчет следующей даты срабатываения
///// </summary>
///// <returns></returns>
//private async Task HandlerAsync(ITemplateService templateService, INextRunService nextRunService, IRobotConfigurationService robotConfigurationService)
//{
// logger.LogInformation("Начинаю обновлять NextRun по расписанию");
// await UpdateNextRunAsync(templateService, nextRunService, robotConfigurationService);
// logger.LogInformation($"Завершено обновление полей NextRun.");
//}
//private async Task UpdateNextRunAsync(ITemplateService templateService, INextRunService nextRunService, IRobotConfigurationService robotConfigurationService)
//{
// // выбираем все шаблоны с просроченным nextRun в статусе Used
// var templatesForUpdate = await templateService.Get()
// .Include(t => t.RobotConfigurations)
// .Where(t =>
// t.StatusTypeId == TemplateStatusTypeEnum.Used
// && t.NextRun < DateTimeOffset.UtcNow
// ).ToListAsync();
// logger.LogInformation("Найдено шаблонов в статусе Used с просроченным NextRun {count} шт.", templatesForUpdate.Count);
// if (!templatesForUpdate.Any())
// return;
// foreach (var template in templatesForUpdate)
// {
// var newNextRun = await nextRunService.GetNextRunForTemplateAsync(template.Id, false);
// if (newNextRun.HasValue)
// {
// template.LastRun = template.NextRun;
// template.NextRun = newNextRun.Value;
// //так как nextRun обновился, пробуем поставить задание на обновление
// var config = robotConfigurationService.GetFromTemplateByRobotCode(RobotsEnum.ScheduleOrder, template);
// robotConfigurationService.SetUpdateTaskStatusIfAllow(config);
// }
// else
// {
// logger.LogError("При расчете nextRun для шаблона {templateId}, '{templateName}', nextRun=null. Это значит что при расчете возникла ошибка.", template.Id, template.Name);
// }
// }
// if (await templateService.CommitAsync(new HistoryInitiator { InitiatorComment = "Обновлён NextRun", InitiatorParrComponentId = ParrComponentsEnum.NextRun }))
// {
// logger.LogInformation("Обновлены значения полей NextRun для шаблонов в статусе Used, {count} шт.", templatesForUpdate.Count);
// }
// else
// {
// logger.LogError("Ошибка при обновлении значений полей NextRun, для шаблонов в статусе Used, {count} шт.", templatesForUpdate.Count);
// }
//}
}
}

View File

@@ -99,81 +99,5 @@ namespace PARR.NextRun
}
}
///// <summary>
///// Обновить все NextRun в JobGroup
///// </summary>
///// <param name="jobGroupId"></param>
///// <returns></returns>
//private async Task UpdateNextRunAsync(NextRunUpdateMq queryMq)
//{
// using var scope = serviceProvider.CreateScope();
// var templateService = scope.ServiceProvider.GetRequiredService<ITemplateService>();
// var nextRunService = scope.ServiceProvider.GetRequiredService<INextRunService>();
// var robotConfigurationService = scope.ServiceProvider.GetRequiredService<IRobotConfigurationService>();
// // Берем шаблоны только в статусе Used
// var templates = await templateService.Get()
// .Include(t => t.RobotConfigurations)
// .Where(t =>
// t.Job!.GroupId == queryMq.JobGroupId
// && t.StatusTypeId == TemplateStatusTypeEnum.Used
// ).ToListAsync();
// logger.LogInformation("Найдено шаблонов {count} шт. в статусе Used в группе работ {jobGroupId}", templates.Count, queryMq.JobGroupId);
// if (!templates.Any())
// return;
// var updatedTemplates = 0;
// foreach (var template in templates)
// {
// var newNextRun = await nextRunService.GetNextRunForTemplateAsync(template.Id, false);
// if (newNextRun == null)
// {
// logger.LogError("При расчете nextRun для шаблона {templateId}, {templateName} вернулся null", template.Id, template.Name);
// continue;
// }
// if (template.NextRun != newNextRun)
// {
// logger.LogInformation("Обновлен nextRun для шаблона {templateId}, {templateName}, newNextRun: {newNextRun}, oldNextRun: {oldNextRun}",
// template.Id, template.Name, newNextRun, template.NextRun);
// template.LastRun = template.NextRun;
// template.NextRun = newNextRun.Value;
// //так как nextRun обновился, пробуем поставить задание на обновление
// var config = robotConfigurationService.GetFromTemplateByRobotCode(RobotsEnum.ScheduleOrder, template);
// robotConfigurationService.SetUpdateTaskStatusIfAllow(config);
// updatedTemplates++;
// }
// else
// {
// logger.LogDebug("Не требуется обновлять nextRun для шаблона {templateId}, {templateName}. Рассчитанный и исходный равны. NextRun: {NextRun}",
// template.Id, template.Name, template.NextRun);
// }
// }
// if (updatedTemplates > 0)
// {
// if (await templateService.CommitAsync(queryMq.Initiator))
// {
// logger.LogInformation("Успешно обновлены nextRun у {count} шаблонов, группа работ: {jobGroupId}", updatedTemplates, queryMq.JobGroupId);
// }
// else
// {
// logger.LogError("При сохранении nextRun для шаблонов {count} шт, произошла ошибка при сохранении в БД. JobGroupId: {jobGroupId}", updatedTemplates, queryMq.JobGroupId);
// }
// }
// else
// {
// logger.LogInformation("Для группы работ {jobGroupId}, все nextRun актуальны. Нечего обновлять.", queryMq.JobGroupId);
// }
//}
}
}