feat(api, dal, nextRun): переделал вызов рассчета NextRun на INextRunService
This commit is contained in:
@@ -24,21 +24,21 @@ namespace PARR.API.Controllers.V1
|
||||
private readonly IClientService clientService;
|
||||
private readonly ITemplateService templateService;
|
||||
private readonly IUnitService unitService;
|
||||
private readonly IEsppScheduleTransformService esppScheduleTransformService;
|
||||
//private readonly IEsppScheduleTransformService esppScheduleTransformService;
|
||||
private readonly ILogger<AgentTaskController> logger;
|
||||
|
||||
public AgentTaskController(
|
||||
IClientService clientService,
|
||||
ITemplateService templateService,
|
||||
IUnitService unitService,
|
||||
IEsppScheduleTransformService esppScheduleTransformService,
|
||||
//IEsppScheduleTransformService esppScheduleTransformService,
|
||||
ILogger<AgentTaskController> logger
|
||||
)
|
||||
{
|
||||
this.clientService = clientService;
|
||||
this.templateService = templateService;
|
||||
this.unitService = unitService;
|
||||
this.esppScheduleTransformService = esppScheduleTransformService;
|
||||
//this.esppScheduleTransformService = esppScheduleTransformService;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@@ -51,82 +51,84 @@ namespace PARR.API.Controllers.V1
|
||||
[HttpGet(ApiRoutes.AgentTask.GetByIp)]
|
||||
public async Task<IActionResult> GetByClientIp([FromQuery] AgentTaskGetByIpQuery request)
|
||||
{
|
||||
//ПАРР-ДВС-ПТК__ВРТ-DVGD-SDMI-WEB-01-ДВС__ПРОЧЕЕ(РАБОТЫ)
|
||||
//10.99.253.65
|
||||
//2023-10-16
|
||||
|
||||
var ip = request.Ip ?? clientService.GetClientIp()?.ToString();
|
||||
return Ok("Метод не реализован");
|
||||
////ПАРР-ДВС-ПТК__ВРТ-DVGD-SDMI-WEB-01-ДВС__ПРОЧЕЕ(РАБОТЫ)
|
||||
////10.99.253.65
|
||||
////2023-10-16
|
||||
|
||||
if (string.IsNullOrEmpty(ip))
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Client IP address is null." } }));
|
||||
//var ip = request.Ip ?? clientService.GetClientIp()?.ToString();
|
||||
|
||||
//var date = request.Date ?? DateTimeOffset.UtcNow;
|
||||
var date = DateTimeOffset.UtcNow;
|
||||
//if (string.IsNullOrEmpty(ip))
|
||||
// return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Client IP address is null." } }));
|
||||
|
||||
//Агент получает задания, если `IsAgent = true`, шаблон и расписания активны, и статус синхронизации шаблона и расписания `= Ok`, и `NextRun = сегодня`, так же если у ApplicationInWork есть расписание.
|
||||
////var date = request.Date ?? DateTimeOffset.UtcNow;
|
||||
//var date = DateTimeOffset.UtcNow;
|
||||
|
||||
// С одним 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.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.Job!.Group!.EsppSchValues.Any()//.ApplicationsInWork.EsppSchValues.Any()
|
||||
).ToListAsync();
|
||||
////Агент получает задания, если `IsAgent = true`, шаблон и расписания активны, и статус синхронизации шаблона и расписания `= Ok`, и `NextRun = сегодня`, так же если у ApplicationInWork есть расписание.
|
||||
|
||||
if (!templates.Any())
|
||||
return NoContent();
|
||||
//// С одним 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.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.Job!.Group!.EsppSchValues.Any()//.ApplicationsInWork.EsppSchValues.Any()
|
||||
// ).ToListAsync();
|
||||
|
||||
var response = new AgentTaskMinResponse
|
||||
{
|
||||
Scheduled = new List<AgentTaskMinScheduleResponse>()
|
||||
};
|
||||
//if (!templates.Any())
|
||||
// return NoContent();
|
||||
|
||||
foreach (var template in templates)
|
||||
{
|
||||
//var templateSchedule = await esppScheduleTransformService.GetNextScheduleAsync(template.ApplicationInWorkId, template.ApplicationsInWork!.LastRun ?? template.ApplicationsInWork!.NextRun);
|
||||
var templateSchedule = await esppScheduleTransformService.GetNextScheduleAsync(template.Job!.GroupId, template.NextRun);
|
||||
//var response = new AgentTaskMinResponse
|
||||
//{
|
||||
// Scheduled = new List<AgentTaskMinScheduleResponse>()
|
||||
//};
|
||||
|
||||
if (!templateSchedule.Any())
|
||||
{
|
||||
logger.LogWarning($"Запросили раписание для агента по NextRun и вернулся пустой список! Такого не должно быть! " +
|
||||
$"JobGroupId: {template.Job.GroupId}, latRun: {template.LastRun}, NextRun: {template.NextRun}, ip: {ip}, date: {date}");
|
||||
continue;
|
||||
}
|
||||
//foreach (var template in templates)
|
||||
//{
|
||||
// //var templateSchedule = await esppScheduleTransformService.GetNextScheduleAsync(template.ApplicationInWorkId, template.ApplicationsInWork!.LastRun ?? template.ApplicationsInWork!.NextRun);
|
||||
// var templateSchedule = await esppScheduleTransformService.GetNextScheduleAsync(template.Job!.GroupId, template.NextRun);
|
||||
|
||||
if (string.IsNullOrEmpty(template.Job.Group!.AgentName) && string.IsNullOrEmpty(template.Job.Group!.AgentScript))
|
||||
{
|
||||
logger.LogWarning($"Запросили задание для агента с пустыми значениями AgentName && AgentScript. Такого не должно быть! " +
|
||||
$"JobGroupId: {template.Job.GroupId}, AgentName: {template.Job.Group.AgentName}, AgentScript: {template.Job.Group.AgentScript} , ip: {ip}, date: {date}");
|
||||
continue;
|
||||
}
|
||||
// if (!templateSchedule.Any())
|
||||
// {
|
||||
// logger.LogWarning($"Запросили раписание для агента по NextRun и вернулся пустой список! Такого не должно быть! " +
|
||||
// $"JobGroupId: {template.Job.GroupId}, latRun: {template.LastRun}, NextRun: {template.NextRun}, ip: {ip}, date: {date}");
|
||||
// continue;
|
||||
// }
|
||||
|
||||
templateSchedule.ForEach(item => response.Scheduled.Add(new AgentTaskMinScheduleResponse
|
||||
{
|
||||
Name = template.Job.Group.AgentName ?? "",
|
||||
Script = template.Job.Group.AgentScript ?? "",
|
||||
StartAt = item,
|
||||
TemplateId = template.Id
|
||||
}));
|
||||
}
|
||||
// if (string.IsNullOrEmpty(template.Job.Group!.AgentName) && string.IsNullOrEmpty(template.Job.Group!.AgentScript))
|
||||
// {
|
||||
// logger.LogWarning($"Запросили задание для агента с пустыми значениями AgentName && AgentScript. Такого не должно быть! " +
|
||||
// $"JobGroupId: {template.Job.GroupId}, AgentName: {template.Job.Group.AgentName}, AgentScript: {template.Job.Group.AgentScript} , ip: {ip}, date: {date}");
|
||||
// continue;
|
||||
// }
|
||||
|
||||
if (!response.Scheduled.Any())
|
||||
return NoContent();
|
||||
// templateSchedule.ForEach(item => response.Scheduled.Add(new AgentTaskMinScheduleResponse
|
||||
// {
|
||||
// Name = template.Job.Group.AgentName ?? "",
|
||||
// Script = template.Job.Group.AgentScript ?? "",
|
||||
// StartAt = item,
|
||||
// TemplateId = template.Id
|
||||
// }));
|
||||
//}
|
||||
|
||||
response.Scheduled = response.Scheduled.OrderBy(t => t.StartAt).ToList();
|
||||
//if (!response.Scheduled.Any())
|
||||
// return NoContent();
|
||||
|
||||
logger.LogInformation($"Агент с IP-адресом {ip} получил задания: [{string.Join(';', response.Scheduled.Select(s => $"StartAt:{s.StartAt}, Name:{s.Name}, TemplateId:{s.TemplateId}"))}]");
|
||||
//response.Scheduled = response.Scheduled.OrderBy(t => t.StartAt).ToList();
|
||||
|
||||
return Ok(response);
|
||||
//logger.LogInformation($"Агент с IP-адресом {ip} получил задания: [{string.Join(';', response.Scheduled.Select(s => $"StartAt:{s.StartAt}, Name:{s.Name}, TemplateId:{s.TemplateId}"))}]");
|
||||
|
||||
//return Ok(response);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ using PARR.DAL.Contracts;
|
||||
using PARR.DAL.DomainServices.Shortcodes;
|
||||
using PARR.DAL.DomainServices.Shortcodes.Models;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.NextRunServices;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
using PARR.DAL.TransformServices;
|
||||
|
||||
@@ -25,31 +26,34 @@ namespace PARR.API.Controllers.V1
|
||||
private readonly IMapper mapper;
|
||||
private readonly SettingsFromDb settingsFromDb;
|
||||
private readonly IRobotConfigurationService robotConfigurationService;
|
||||
private readonly IEsppScheduleTransformService esppScheduleTransformService;
|
||||
//private readonly IEsppScheduleTransformService esppScheduleTransformService;
|
||||
private readonly ILogger<RobotTaskController> logger;
|
||||
private readonly IClientService clientService;
|
||||
private readonly IRobotHistoryService robotHistoryService;
|
||||
private readonly IShortcodesService shortcodesService;
|
||||
private readonly INextRunService nextRunService;
|
||||
|
||||
public RobotTaskController(
|
||||
IMapper mapper,
|
||||
SettingsFromDb settingsFromDb,
|
||||
IRobotConfigurationService robotConfigurationService,
|
||||
IEsppScheduleTransformService esppScheduleTransformService,
|
||||
//IEsppScheduleTransformService esppScheduleTransformService,
|
||||
ILogger<RobotTaskController> logger,
|
||||
IClientService clientService,
|
||||
IRobotHistoryService robotHistoryService,
|
||||
IShortcodesService shortcodesService
|
||||
IShortcodesService shortcodesService,
|
||||
INextRunService nextRunService
|
||||
)
|
||||
{
|
||||
this.mapper = mapper;
|
||||
this.settingsFromDb = settingsFromDb;
|
||||
this.robotConfigurationService = robotConfigurationService;
|
||||
this.esppScheduleTransformService = esppScheduleTransformService;
|
||||
//this.esppScheduleTransformService = esppScheduleTransformService;
|
||||
this.logger = logger;
|
||||
this.clientService = clientService;
|
||||
this.robotHistoryService = robotHistoryService;
|
||||
this.shortcodesService = shortcodesService;
|
||||
this.nextRunService = nextRunService;
|
||||
}
|
||||
|
||||
|
||||
@@ -306,7 +310,8 @@ namespace PARR.API.Controllers.V1
|
||||
//пока у нас выключено автораспределение, считает по refDate
|
||||
//TODO: когда заработает автораспределение, будем думать!!!!!
|
||||
|
||||
var nextRun = await esppScheduleTransformService.GetNextDateAsync(template.Job!.GroupId, template!.Job!.Group!.ReferenceDate);
|
||||
//var nextRun = await esppScheduleTransformService.GetNextDateAsync(template.Job!.GroupId, template!.Job!.Group!.ReferenceDate);
|
||||
var nextRun = await nextRunService.GetNextRunForTemplateAsync(template.Id, false);
|
||||
|
||||
if (nextRun != template.NextRun)
|
||||
{
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace PARR.API.Controllers.V1
|
||||
public class TestController : BaseApiController
|
||||
{
|
||||
private readonly IClientService clientService;
|
||||
private readonly IEsppScheduleTransformService esppScheduleTransformService;
|
||||
//private readonly IEsppScheduleTransformService esppScheduleTransformService;
|
||||
private readonly IRedisCacheService redisCacheService;
|
||||
private readonly IWeekendDayService weekendDayService;
|
||||
private readonly IUnitService unitService;
|
||||
@@ -37,7 +37,7 @@ namespace PARR.API.Controllers.V1
|
||||
|
||||
public TestController(
|
||||
IClientService clientService,
|
||||
IEsppScheduleTransformService esppScheduleTransformService,
|
||||
//IEsppScheduleTransformService esppScheduleTransformService,
|
||||
IRedisCacheService redisCacheService,
|
||||
IWeekendDayService weekendDayService,
|
||||
IUnitService unitService,
|
||||
@@ -49,7 +49,7 @@ namespace PARR.API.Controllers.V1
|
||||
)
|
||||
{
|
||||
this.clientService = clientService;
|
||||
this.esppScheduleTransformService = esppScheduleTransformService;
|
||||
//this.esppScheduleTransformService = esppScheduleTransformService;
|
||||
this.redisCacheService = redisCacheService;
|
||||
this.weekendDayService = weekendDayService;
|
||||
this.unitService = unitService;
|
||||
@@ -76,32 +76,32 @@ namespace PARR.API.Controllers.V1
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Получить следующую дату запуска
|
||||
/// </summary>
|
||||
/// <param name="applicationInWorkId"></param>
|
||||
/// <param name="lastRunDate"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.Test.GetNextScheduleDate)]
|
||||
public async Task<IActionResult> GetNextScheduleDate([FromRoute] Guid applicationInWorkId, [FromRoute] DateTimeOffset lastRunDate)
|
||||
{
|
||||
var result = await esppScheduleTransformService.GetNextDateAsync(applicationInWorkId, lastRunDate);
|
||||
return Ok(result);
|
||||
}
|
||||
///// <summary>
|
||||
///// Получить следующую дату запуска
|
||||
///// </summary>
|
||||
///// <param name="applicationInWorkId"></param>
|
||||
///// <param name="lastRunDate"></param>
|
||||
///// <returns></returns>
|
||||
//[HttpGet(ApiRoutes.Test.GetNextScheduleDate)]
|
||||
//public async Task<IActionResult> GetNextScheduleDate([FromRoute] Guid applicationInWorkId, [FromRoute] DateTimeOffset lastRunDate)
|
||||
//{
|
||||
// var result = await esppScheduleTransformService.GetNextDateAsync(applicationInWorkId, lastRunDate);
|
||||
// return Ok(result);
|
||||
//}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Получить следующее расписание
|
||||
/// </summary>
|
||||
/// <param name="applicationInWorkId"></param>
|
||||
/// <param name="lastRunDate"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.Test.GetNextSchedule)]
|
||||
public async Task<IActionResult> GetNextSchedule([FromRoute] Guid applicationInWorkId, [FromRoute] DateTimeOffset lastRunDate)
|
||||
{
|
||||
var result = await esppScheduleTransformService.GetNextScheduleAsync(applicationInWorkId, lastRunDate);
|
||||
return Ok(result);
|
||||
}
|
||||
///// <summary>
|
||||
///// Получить следующее расписание
|
||||
///// </summary>
|
||||
///// <param name="applicationInWorkId"></param>
|
||||
///// <param name="lastRunDate"></param>
|
||||
///// <returns></returns>
|
||||
//[HttpGet(ApiRoutes.Test.GetNextSchedule)]
|
||||
//public async Task<IActionResult> GetNextSchedule([FromRoute] Guid applicationInWorkId, [FromRoute] DateTimeOffset lastRunDate)
|
||||
//{
|
||||
// var result = await esppScheduleTransformService.GetNextScheduleAsync(applicationInWorkId, lastRunDate);
|
||||
// return Ok(result);
|
||||
//}
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user