feat(all): ! Критические изменения логики работы всех сервисорв, База Данных имееет неокончательную версию. Template, Scheduler переведены на работу с Unit+Job+JobGroup вместо Host+ApplicationsInWork

This commit is contained in:
Mikhail Kuznetsov
2025-06-25 14:17:34 +10:00
parent 1b867585d8
commit 03c7852378
54 changed files with 5176 additions and 989 deletions

View File

@@ -10,6 +10,7 @@ using PARR.API.Services.Interfaces;
using PARR.Constants;
using PARR.DAL.Contracts;
using PARR.DAL.Services.Interfaces;
using PARR.DAL.Services.Interfaces.Unit;
using PARR.DAL.TransformServices;
namespace PARR.API.Controllers.V1
@@ -22,18 +23,21 @@ namespace PARR.API.Controllers.V1
{
private readonly IClientService clientService;
private readonly ITemplateService templateService;
private readonly IUnitService unitService;
private readonly IEsppScheduleTransformService esppScheduleTransformService;
private readonly ILogger<AgentTaskController> logger;
public AgentTaskController(
IClientService clientService,
ITemplateService templateService,
IUnitService unitService,
IEsppScheduleTransformService esppScheduleTransformService,
ILogger<AgentTaskController> logger
)
{
this.clientService = clientService;
this.templateService = templateService;
this.unitService = unitService;
this.esppScheduleTransformService = esppScheduleTransformService;
this.logger = logger;
}
@@ -62,19 +66,21 @@ namespace PARR.API.Controllers.V1
//Агент получает задания, если `IsAgent = true`, шаблон и расписания активны, и статус синхронизации шаблона и расписания `= Ok`, и `NextRun = сегодня`, так же если у ApplicationInWork есть расписание.
// С одним IP может быть несколько информационных систем, так что может быть несколько хостов
var units = await unitService.GetWithIncludes().AsNoTracking().Where(t => t.UnitValues.Any(v => v.Field!.AihitName == "IP_АДРЕС" && v.Value!.Value == ip)).ToListAsync();
var templates = await templateService.Get()
.Include(t => t.RobotConfigurations)
.Include(t => t.ApplicationsInWork)
.ThenInclude(t => t!.EsppSchValues)
.Include(t => t.Host)
.Where(t => t.Host!.IP == ip
&& t.ApplicationsInWork!.IsAgent == true
.Include(t => t.Job)
.ThenInclude(t=>t!.Group)
.ThenInclude(t => t!.EsppSchValues)
.Include(t => t.Unit)
.Where(t => units.Any(u=>u.Id == t.UnitId)
//&& t.ApplicationsInWork!.IsAgent == true//TODO Migration to job
&& t.IsActiveTemplate == true
&& t.IsActiveSchedule == true
//&& t.ApplicationsInWork!.NextRun.DateTime.Date == date.Date.Date
&& t.NextRun.DateTime.Date == date.Date.Date
&& t.RobotConfigurations.All(c => c.TaskStatusCode == (int)TaskStatusEnum.Ok)
&& t.ApplicationsInWork.EsppSchValues.Any()
&& t.Job!.Group!.EsppSchValues.Any()//.ApplicationsInWork.EsppSchValues.Any()
).ToListAsync();
if (!templates.Any())
@@ -88,26 +94,26 @@ namespace PARR.API.Controllers.V1
foreach (var template in templates)
{
//var templateSchedule = await esppScheduleTransformService.GetNextScheduleAsync(template.ApplicationInWorkId, template.ApplicationsInWork!.LastRun ?? template.ApplicationsInWork!.NextRun);
var templateSchedule = await esppScheduleTransformService.GetNextScheduleAsync(template.ApplicationInWorkId, template.NextRun);
var templateSchedule = await esppScheduleTransformService.GetNextScheduleAsync(template.Job!.GroupId, template.NextRun);
if (!templateSchedule.Any())
{
logger.LogWarning($"Запросили раписание для агента по NextRun и вернулся пустой список! Такого не должно быть! " +
$"ApplicationInWorkId: {template.ApplicationInWorkId}, latRun: {template.LastRun}, NextRun: {template.NextRun}, ip: {ip}, date: {date}");
$"JobGroupId: {template.Job.GroupId}, latRun: {template.LastRun}, NextRun: {template.NextRun}, ip: {ip}, date: {date}");
continue;
}
if (string.IsNullOrEmpty(template.ApplicationsInWork.AgentName) && string.IsNullOrEmpty(template.ApplicationsInWork.AgentScript))
if (string.IsNullOrEmpty(template.Job.Group!.AgentName) && string.IsNullOrEmpty(template.Job.Group!.AgentScript))
{
logger.LogWarning($"Запросили задание для агента с пустыми значениями AgentName && AgentScript. Такого не должно быть! " +
$"ApplicationInWorkId: {template.ApplicationInWorkId}, AgentName: {template.ApplicationsInWork.AgentName}, AgentScript: {template.ApplicationsInWork.AgentScript} , ip: {ip}, date: {date}");
$"JobGroupId: {template.Job.GroupId}, AgentName: {template.Job.Group.AgentName}, AgentScript: {template.Job.Group.AgentScript} , ip: {ip}, date: {date}");
continue;
}
templateSchedule.ForEach(item => response.Scheduled.Add(new AgentTaskMinScheduleResponse
{
Name = template.ApplicationsInWork!.AgentName ?? "",
Script = template.ApplicationsInWork!.AgentScript ?? "",
Name = template.Job.Group.AgentName ?? "",
Script = template.Job.Group.AgentScript ?? "",
StartAt = item,
TemplateId = template.Id
}));