feat(distributor): первая версия распределителя
This commit is contained in:
79
PARR.DAL/NextRunServices/NextRunService.cs
Normal file
79
PARR.DAL/NextRunServices/NextRunService.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
using PARR.DAL.Services.Interfaces.Job;
|
||||
using PARR.DAL.TransformServices;
|
||||
|
||||
namespace PARR.DAL.NextRunServices
|
||||
{
|
||||
internal class NextRunService : INextRunService
|
||||
{
|
||||
private readonly ILogger<NextRunService> logger;
|
||||
private readonly ITemplateService templateService;
|
||||
private readonly IJobGroupService jobGroupService;
|
||||
private readonly IEsppScheduleTransformService esppScheduleTransformService;
|
||||
|
||||
public NextRunService(
|
||||
ILogger<NextRunService> logger,
|
||||
ITemplateService templateService,
|
||||
IJobGroupService jobGroupService,
|
||||
IEsppScheduleTransformService esppScheduleTransformService
|
||||
)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.templateService = templateService;
|
||||
this.jobGroupService = jobGroupService;
|
||||
this.esppScheduleTransformService = esppScheduleTransformService;
|
||||
}
|
||||
|
||||
|
||||
public Task<List<(Guid TemplateId, DateTimeOffset NextRun)>> GetNextRunForJobGroupWithAutoDistributionAsync(Guid jobGroupId)
|
||||
{
|
||||
//TODO:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
public async Task<DateTimeOffset> GetNextRunForJobGroupWithEsppSchedulleAsync(Guid jobGroupId)
|
||||
{
|
||||
var jobGroup = await jobGroupService.Get().AsNoTracking().FirstOrDefaultAsync(t => t.Id == jobGroupId);
|
||||
|
||||
if (jobGroup == null)
|
||||
{
|
||||
logger.LogError("Не найдена группа работ с Id: {jobGroupId}.", jobGroupId);
|
||||
throw new ArgumentNullException(nameof(jobGroupId), $"Не найдена группа работ с Id: {jobGroupId}");
|
||||
}
|
||||
|
||||
// Берем из обычного расписания ЕСПП
|
||||
return await esppScheduleTransformService.GetNextDateAsync(jobGroupId, jobGroup.ReferenceDate);
|
||||
}
|
||||
|
||||
|
||||
public async Task<DateTimeOffset> GetNextRunForTemplate(Guid templateId)
|
||||
{
|
||||
var template = await templateService.Get()
|
||||
.Include(t => t.Job).ThenInclude(t => t.Group)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync(t => t.Id == templateId);
|
||||
|
||||
if (template == null)
|
||||
{
|
||||
logger.LogError("Не найдена шаблон с Id: {templateId}.", templateId);
|
||||
throw new ArgumentNullException(nameof(templateId), $"Не найдена шаблон с Id: {templateId}");
|
||||
}
|
||||
|
||||
if (template.Job!.Group!.IsAutoDistributionEnabled == true)
|
||||
{
|
||||
// включено автораспределение
|
||||
//TODO: !!!!!!!!!!!!!!!! добавить метод рассчета с учетом распределения
|
||||
throw new NotImplementedException("добавить метод рассчета с учетом распределения");
|
||||
}
|
||||
else
|
||||
{
|
||||
// считаем как ЕСПП
|
||||
return await esppScheduleTransformService.GetNextDateAsync(template.Job.Group.Id, template.Job.Group.ReferenceDate);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user