feat(api, dal, esppOrderLoader, esppScheduleSync, generatorTemplates, nextRun):
This commit is contained in:
@@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user