feat(api, dal, esppOrderLoader, esppScheduleSync, generatorTemplates, nextRun):

This commit is contained in:
Mikhail Trubnikov
2024-07-03 15:19:09 +10:00
parent f8bd15cd6f
commit a4f6089438
10 changed files with 80 additions and 50 deletions

View File

@@ -36,13 +36,14 @@ namespace PARR.NextRun
{
using (var scope = serviceProvider.CreateScope())
{
var appInWorkService = scope.ServiceProvider.GetService<IApplicationsInWorkService>();
//var appInWorkService = scope.ServiceProvider.GetService<IApplicationsInWorkService>();
var esppSchService = scope.ServiceProvider.GetService<IEsppScheduleTransformService>();
var templateService = scope.ServiceProvider.GetService<ITemplateService>();
if (appInWorkService == null || esppSchService == null)
throw new Exception("Не смог получить серивс IApplicationsInWorkService или IEsppScheduleTransformService");
if (templateService == null || esppSchService == null)
throw new Exception("Не смог получить серивс ITemplateService или IEsppScheduleTransformService");
await HandlerAsync(appInWorkService, esppSchService);
await HandlerAsync(templateService, esppSchService);
}
}, workerSettings.RepeatEvery);
}
@@ -52,30 +53,30 @@ namespace PARR.NextRun
/// Рассчет следующей даты срабатываения
/// </summary>
/// <returns></returns>
private async Task HandlerAsync(IApplicationsInWorkService applicationsInWorkService, IEsppScheduleTransformService esppScheduleTransformService)
private async Task HandlerAsync(ITemplateService templateService, IEsppScheduleTransformService esppScheduleTransformService)
{
var objs = await applicationsInWorkService.Get().Where(t => t.NextRun < DateTimeOffset.UtcNow).ToListAsync();
var templates = await templateService.Get().Where(t => t.NextRun < DateTimeOffset.UtcNow).ToListAsync();
logger.LogDebug($"Объектов для обновления: {objs.Count()} шт.");
logger.LogDebug($"Шаблонов для обновления: {templates.Count()} шт.");
int errorsCount = 0;
foreach (var obj in objs)
foreach (var template in templates)
{
var nextRun = await esppScheduleTransformService.GetNextDateAsync(obj.Id, obj.NextRun);
obj.LastRun = obj.NextRun;
obj.NextRun = nextRun;
var nextRun = await esppScheduleTransformService.GetNextDateAsync(template.ApplicationInWorkId, template.NextRun);
template.LastRun = template.NextRun;
template.NextRun = nextRun;
if (await applicationsInWorkService.CommitAsync())
logger.LogDebug($"Обновлено значение полей NextRun: {obj.NextRun}, LastRun: {obj.LastRun} для строки {obj.Id}");
if (await templateService.CommitAsync())
logger.LogDebug($"Обновлены значения полей NextRun: {template.NextRun}, LastRun: {template.LastRun} для шаблона {template.Name}, {template.Id}");
else
{
logger.LogError($"Ошибка при обновлении значения полей NextRun {obj.NextRun}, LastRun: {obj.LastRun} для строки {obj.Id}");
logger.LogError($"Ошибка при обновлении значений полей NextRun: {template.NextRun}, LastRun: {template.LastRun} для шаблона {template.Name}, {template.Id}");
errorsCount++;
}
}
logger.LogInformation($"Завершено обновление полей NextRun. Полей в задании: {objs.Count()}, обновлено: {objs.Count() - errorsCount}, ошибок: {errorsCount}");
logger.LogInformation($"Завершено обновление полей NextRun. Полей в задании: {templates.Count()}, обновлено: {templates.Count() - errorsCount}, ошибок: {errorsCount}");
}
}
}