feat(api): Логика смены статусов для заданий робота. RobotTaskController
This commit is contained in:
@@ -15,18 +15,21 @@ namespace PARR.GeneratorTemplates.Services
|
||||
private readonly IHostService hostService;
|
||||
private readonly ILogger<TemplateManager> logger;
|
||||
private readonly SettingsFromDb settingsFromDb;
|
||||
private readonly IRobotConfigurationService robotConfigurationService;
|
||||
|
||||
public TemplateManager(
|
||||
ITemplateService templateService,
|
||||
IHostService hostService,
|
||||
ILogger<TemplateManager> logger,
|
||||
SettingsFromDb settingsFromDb
|
||||
SettingsFromDb settingsFromDb,
|
||||
IRobotConfigurationService robotConfigurationService
|
||||
)
|
||||
{
|
||||
this.templateService = templateService;
|
||||
this.hostService = hostService;
|
||||
this.logger = logger;
|
||||
this.settingsFromDb = settingsFromDb;
|
||||
this.robotConfigurationService = robotConfigurationService;
|
||||
}
|
||||
|
||||
public async Task CreateTemplates(GeneratorTemplateMq query)
|
||||
@@ -84,8 +87,9 @@ namespace PARR.GeneratorTemplates.Services
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Name = TemplateHelpers.GenerateTemplateName(settingsFromDb.TemplatePrefixName, host.Ek, appInWork.Work!.Name),
|
||||
IsActive = true,
|
||||
StatusCode = (int)StatusTemplateEnum.Creating,
|
||||
IsActiveTemplate = true,
|
||||
IsActiveSchedule = true,
|
||||
StatusCode = (int)TaskStatusEnum.Creating,
|
||||
ApplicationInWorkId = appInWork.Id,
|
||||
HostId = host.Id,
|
||||
RobotAttemptsNumber = 0,
|
||||
@@ -100,7 +104,7 @@ namespace PARR.GeneratorTemplates.Services
|
||||
else
|
||||
{
|
||||
logger.LogInformation($"Создан шаблон: Name: {template.Name}, ApplicationInWorkId: {template.ApplicationInWorkId}, " +
|
||||
$"HostId: {template.HostId}, IsActive: {template.IsActive}, StatusCode: {template.StatusCode}");
|
||||
$"HostId: {template.HostId}, IsActive: {template.IsActiveTemplate}, StatusCode: {template.StatusCode}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,8 +119,9 @@ namespace PARR.GeneratorTemplates.Services
|
||||
var queryTemplates = templateService.Get()
|
||||
.Include(t => t.Host)
|
||||
.Include(t => t.ApplicationsInWork)
|
||||
.Include(t => t.RobotConfigurations)
|
||||
.Where(t =>
|
||||
t.IsActive == true
|
||||
(t.IsActiveTemplate == true || t.IsActiveSchedule == true)
|
||||
&& t.ApplicationsInWork!.ApplicationId == query.ApplicationId
|
||||
&& t.ApplicationsInWork!.WorkId == query.WorkId
|
||||
&& EF.Functions.Like(t.Host!.Ek.ToLower(), ekPattern)
|
||||
@@ -138,12 +143,23 @@ namespace PARR.GeneratorTemplates.Services
|
||||
|
||||
existTemplates.ForEach(item =>
|
||||
{
|
||||
item.IsActive = false;
|
||||
item.StatusCode = (int)StatusTemplateEnum.Updating;
|
||||
item.DateModified = DateTimeOffset.UtcNow;
|
||||
item.RobotAttemptsNumber = 0;
|
||||
item.RobotLastStatusUpdated = null;
|
||||
item.RobotStatusCode = (int)RobotStatusEnum.Wait;
|
||||
|
||||
if (item.IsActiveTemplate)
|
||||
{
|
||||
item.IsActiveTemplate = false;
|
||||
//необходимо обновить шаблон
|
||||
var config = robotConfigurationService.GetFromTemplateByRobotCode(RobotsEnum.TemplateOrder, ref item);
|
||||
robotConfigurationService.ChangeTaskStatus(TaskStatusEnum.Updating, ref config);
|
||||
}
|
||||
|
||||
if (item.IsActiveSchedule)
|
||||
{
|
||||
item.IsActiveSchedule = false;
|
||||
//необходимо обновить расписание
|
||||
var config = robotConfigurationService.GetFromTemplateByRobotCode(RobotsEnum.ScheduleOrder, ref item);
|
||||
robotConfigurationService.ChangeTaskStatus(TaskStatusEnum.Updating, ref config);
|
||||
}
|
||||
});
|
||||
|
||||
if (await templateService.CommitAsync())
|
||||
|
||||
Reference in New Issue
Block a user