feat: Слияние веток. Миграции для Tasks
This commit is contained in:
@@ -49,20 +49,7 @@
|
||||
|
||||
public const string GetNextRun = Base + "/tests/next-run";
|
||||
|
||||
public const string GetNextScheduleDate = Base + "/tests/next-schedule-date/" + paramApplicationInWorkId + "/" + paramDate;
|
||||
|
||||
public const string GetNextSchedule = Base + "/tests/next-schedule/" + paramApplicationInWorkId + "/" + paramDate;
|
||||
|
||||
public const string CreateCache = Base + "/tests/cache/";
|
||||
|
||||
public const string IsWorkDay = Base + "/tests/is-work-day/";
|
||||
|
||||
public const string TestHandler = Base + "/tests/test/";
|
||||
|
||||
public const string GetWorkDay = Base + "/tests/get-work-day/{date}";
|
||||
|
||||
public const string paramDate = "{lastRunDate}";
|
||||
public const string paramApplicationInWorkId = "{applicationInWorkId}";
|
||||
}
|
||||
|
||||
public static class Template
|
||||
@@ -309,6 +296,11 @@
|
||||
public const string GetByApplicationInWork = BaseStat + "/work-workloads/";
|
||||
}
|
||||
|
||||
public static class Workload
|
||||
{
|
||||
public const string Build = BaseStat + "/workload/build";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Наряды
|
||||
|
||||
34
PARR.API/Controllers/V1/Statistics/StatWorkloadController.cs
Normal file
34
PARR.API/Controllers/V1/Statistics/StatWorkloadController.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using PARR.API.Contracts.V1;
|
||||
using PARR.API.Controllers.V1.Base;
|
||||
using PARR.Constants;
|
||||
|
||||
namespace PARR.API.Controllers.V1.Statistics
|
||||
{
|
||||
/// <summary>
|
||||
/// Статистика загруженности по ЗО, РГ
|
||||
/// </summary>
|
||||
[Authorize(Roles = ParrRoles.EsppRobot.RoleOrAdmin)]
|
||||
public class StatWorkloadController : BaseApiController
|
||||
{
|
||||
public StatWorkloadController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Сформировать отчетность
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost(ApiRoutes.Workload.Build)]
|
||||
public async Task<IActionResult> Build()
|
||||
{
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,12 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using PARR.API.Contracts.V1;
|
||||
using PARR.API.Contracts.V1.Responses.Base;
|
||||
using PARR.API.Controllers.V1.Base;
|
||||
using PARR.API.Services.Interfaces;
|
||||
using PARR.DAL.Cache.Services.Base;
|
||||
using PARR.DAL.DomainServices.UnitFilterService;
|
||||
using PARR.DAL.NextRunServices;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
using PARR.DAL.Services.Interfaces.Job;
|
||||
using PARR.DAL.Services.Interfaces.Unit;
|
||||
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
@@ -19,43 +15,19 @@ namespace PARR.API.Controllers.V1
|
||||
public class TestController : BaseApiController
|
||||
{
|
||||
private readonly IClientService clientService;
|
||||
//private readonly IEsppScheduleTransformService esppScheduleTransformService;
|
||||
private readonly IRedisCacheService redisCacheService;
|
||||
private readonly IWeekendDayService weekendDayService;
|
||||
private readonly IUnitService unitService;
|
||||
private readonly IFieldFilterService fieldFilterService;
|
||||
private readonly IJobService jobService;
|
||||
private readonly IJobUnitFilterService jobUnitFilterService;
|
||||
private readonly IUnitFilterService unitFilterService;
|
||||
private readonly IMapper mapper;
|
||||
private readonly INextRunService nextRunService;
|
||||
private readonly ITemplateService templateService;
|
||||
|
||||
public TestController(
|
||||
IClientService clientService,
|
||||
//IEsppScheduleTransformService esppScheduleTransformService,
|
||||
IRedisCacheService redisCacheService,
|
||||
IWeekendDayService weekendDayService,
|
||||
IUnitService unitService,
|
||||
IFieldFilterService fieldFilterService,
|
||||
IJobService jobService,
|
||||
IJobUnitFilterService jobUnitFilterService,
|
||||
IUnitFilterService unitFilterService,
|
||||
IMapper mapper,
|
||||
INextRunService nextRunService,
|
||||
ITemplateService templateService
|
||||
)
|
||||
{
|
||||
this.clientService = clientService;
|
||||
//this.esppScheduleTransformService = esppScheduleTransformService;
|
||||
this.redisCacheService = redisCacheService;
|
||||
this.weekendDayService = weekendDayService;
|
||||
this.unitService = unitService;
|
||||
this.fieldFilterService = fieldFilterService;
|
||||
this.jobService = jobService;
|
||||
this.jobUnitFilterService = jobUnitFilterService;
|
||||
this.unitFilterService = unitFilterService;
|
||||
this.mapper = mapper;
|
||||
this.nextRunService = nextRunService;
|
||||
this.templateService = templateService;
|
||||
}
|
||||
@@ -92,124 +64,49 @@ 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.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="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost(ApiRoutes.Test.CreateCache)]
|
||||
public async Task<IActionResult> CreateCache([FromBody] CaheRequestTest request)
|
||||
public async Task<IActionResult> CreateCache()
|
||||
{
|
||||
await redisCacheService.SetCachedDataAsync(request.Key, request, TimeSpan.FromMinutes(1));
|
||||
//var val = await redisCacheService.GetCachedDataAsync<object>("96dAoIH/8Q9Bg8VY");
|
||||
|
||||
var fromCache = await redisCacheService.GetCachedDataAsync<CaheRequestTest>(request.Key);
|
||||
//var hashKey = redisCacheService.GetKey(new[] { "test", "mxa" });
|
||||
//var ttl = TimeSpan.FromMinutes(10);
|
||||
|
||||
return Ok(new { fromCache });
|
||||
}
|
||||
//await redisCacheService.SetHashFieldAsync(hashKey, "t1", "val1", ttl);
|
||||
//await redisCacheService.SetHashFieldAsync(hashKey, "t2", "val2");
|
||||
//await redisCacheService.SetHashFieldAsync(hashKey, "t3", "val3");
|
||||
|
||||
//var length = await redisCacheService.GetHashLengthAsync(hashKey);
|
||||
|
||||
/// <summary>
|
||||
/// Проверка, это рабочий день?
|
||||
/// </summary>
|
||||
/// <param name="date"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.Test.IsWorkDay)]
|
||||
public async Task<IActionResult> IsWorkDay([FromQuery] DateOnly date)
|
||||
{
|
||||
return Ok(await weekendDayService.IsWorkDayAsync(date, true));
|
||||
}
|
||||
//var get = await redisCacheService.GetHashFieldAsync<string>(hashKey, "t1");
|
||||
|
||||
//var getAll = await redisCacheService.GetAllHashFieldsAsync<string>(hashKey);
|
||||
|
||||
/// <summary>
|
||||
/// Тестовый метод
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.Test.TestHandler)]
|
||||
public async Task<IActionResult> Test()
|
||||
{
|
||||
//var job = new Job
|
||||
//{
|
||||
// Id = Guid.NewGuid(),
|
||||
// Name = "ВИ-VMWARE ТО-1 Мониторинг и анализ работы виртуальной инфраструктуры",
|
||||
// DateCreated = DateTimeOffset.Now,
|
||||
// TemplateNameMask = "ЭИТИ_%РГ%_%ТНК%_%ЭК%",
|
||||
// TnkId = Guid.Parse("9b7e0251-cb13-427c-ac71-16baa2a111dd")
|
||||
//};
|
||||
//await redisCacheService.DeleteHashFieldAsync(hashKey, "t1");
|
||||
//var getT1 = await redisCacheService.GetHashFieldAsync<string>(hashKey, "t1");
|
||||
|
||||
//var jobDetails = new JobDetails {
|
||||
// Id = Guid.NewGuid(),
|
||||
// UnitFilter = "ВРТ-VMWARE-*",
|
||||
// JobId = job.Id,
|
||||
// ShortDescription = "Мониторинг и анализ работы виртуальной инфраструктуры",
|
||||
// FullDescription = "Проверка журналов (лог-файла) событий (warning, alarm) объектов виртуальной инфраструктуры (ВМ, хост, кластер, датацентр, virtual center и др.)",
|
||||
// Solution = "Работы проведены",
|
||||
// Duration = "7 00:00:00",
|
||||
// ReferenceDate = new DateTimeOffset(2026,01,01,00,00,00,new TimeSpan(0))
|
||||
//};
|
||||
//var exist = await redisCacheService.HashFieldExistsAsync(hashKey, "t2");
|
||||
|
||||
//var fieldFilter = new FieldFilter
|
||||
//{
|
||||
// Id = Guid.NewGuid(),
|
||||
// JobDetailsId = jobDetails.Id,
|
||||
// FieldId = Guid.Parse("08b42860-09a7-4a1f-aa4f-0290e86df884"),
|
||||
// ValueMask = "виртуальный комплекс"
|
||||
//};
|
||||
////await jobService.CreateAsync(job);
|
||||
////await jobService.CommitAsync();
|
||||
//if (await jobService.CreateAsync(job))
|
||||
// if (await jobDetailsService.CreateAsync(jobDetails))
|
||||
// if (await fieldFilterService.CreateAsync(fieldFilter))
|
||||
// await jobService.CommitAsync();
|
||||
//var unit = await unitService.Get().Include(t => t.Parents).Include(t => t.Childs).FirstOrDefaultAsync(t => t.Id == Guid.Parse("01fda0bd-3423-4b12-965b-2947153d1d87"));
|
||||
//await redisCacheService.DeleteHashAsync(hashKey);
|
||||
//var getT_1 = await redisCacheService.GetHashFieldAsync<string>(hashKey, "t1");
|
||||
|
||||
//var parent = unit?.Parents;
|
||||
//var child = unit?.Childs;
|
||||
//await redisCacheService.SetHashTtlAsync(hashKey, ttl);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
//[HttpGet(ApiRoutes.Test.GetWorkDay)]
|
||||
//public async Task<IActionResult> GetWorkDay([FromRoute] DateTimeOffset date)
|
||||
//{
|
||||
// var result = await esppScheduleTransformService.GetWorkDayAsync(date);
|
||||
|
||||
// return Ok(result);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class CaheRequestTest
|
||||
{
|
||||
public required string Key { get; set; }
|
||||
|
||||
public required string Value { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,5 +57,76 @@
|
||||
/// <param name="keyPartsToHash"></param>
|
||||
/// <returns></returns>
|
||||
string GetKey(string[] keyParts, string[]? keyPartsToHash = null);
|
||||
|
||||
|
||||
#region Работа с Hash
|
||||
|
||||
/// <summary>
|
||||
/// Изменить одно поле в Hash
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="hashKey"></param>
|
||||
/// <param name="field"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="ttl">Если указано, обновится у всего Hash. Если не указано и hash не существовал, создастся Hash с бесокнечным ttl</param>
|
||||
/// <returns></returns>
|
||||
Task SetHashFieldAsync<T>(string hashKey, string field, T value, TimeSpan? ttl = null);
|
||||
|
||||
/// <summary>
|
||||
/// Получить значение поля из Hash
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="hashKey"></param>
|
||||
/// <param name="field"></param>
|
||||
/// <returns></returns>
|
||||
Task<T?> GetHashFieldAsync<T>(string hashKey, string field);
|
||||
|
||||
/// <summary>
|
||||
/// Получить все значения из Hash
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="hashKey"></param>
|
||||
/// <returns></returns>
|
||||
Task<Dictionary<string, T>> GetAllHashFieldsAsync<T>(string hashKey);
|
||||
|
||||
/// <summary>
|
||||
/// Удалить одну запись из Hash
|
||||
/// </summary>
|
||||
/// <param name="hashKey"></param>
|
||||
/// <param name="field"></param>
|
||||
/// <returns></returns>
|
||||
Task DeleteHashFieldAsync(string hashKey, string field);
|
||||
|
||||
/// <summary>
|
||||
/// Есть ли запись в Hash
|
||||
/// </summary>
|
||||
/// <param name="hashKey"></param>
|
||||
/// <param name="field"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> HashFieldExistsAsync(string hashKey, string field);
|
||||
|
||||
/// <summary>
|
||||
/// Удалить весь Hash
|
||||
/// </summary>
|
||||
/// <param name="hashKey"></param>
|
||||
/// <returns></returns>
|
||||
Task DeleteHashAsync(string hashKey);
|
||||
|
||||
/// <summary>
|
||||
/// Получить количество записей в Hash
|
||||
/// </summary>
|
||||
/// <param name="hashKey"></param>
|
||||
/// <returns></returns>
|
||||
Task<long> GetHashLengthAsync(string hashKey);
|
||||
|
||||
/// <summary>
|
||||
/// Установить TTL для Hash
|
||||
/// </summary>
|
||||
/// <param name="hashKey"></param>
|
||||
/// <param name="ttl"></param>
|
||||
/// <returns></returns>
|
||||
Task SetHashTtlAsync(string hashKey, TimeSpan ttl);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,26 @@
|
||||
using Microsoft.Extensions.Caching.Distributed;
|
||||
using StackExchange.Redis;
|
||||
using System.Text.Json;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace PARR.DAL.Cache.Services.Base
|
||||
{
|
||||
internal class RedisCacheService : IRedisCacheService
|
||||
{
|
||||
private readonly IDistributedCache cache;
|
||||
private readonly IDatabase redis;
|
||||
|
||||
public RedisCacheService(IDistributedCache cache)
|
||||
public RedisCacheService(
|
||||
IDistributedCache cache,
|
||||
IConnectionMultiplexer connectionMultiplexer
|
||||
)
|
||||
{
|
||||
this.cache = cache;
|
||||
this.redis = connectionMultiplexer.GetDatabase();
|
||||
}
|
||||
|
||||
#region Распределенный кэш IDistributedCache
|
||||
|
||||
public async Task<T?> GetCachedDataAsync<T>(string key)
|
||||
{
|
||||
var jsonData = await cache.GetStringAsync(key);
|
||||
@@ -69,6 +78,85 @@ namespace PARR.DAL.Cache.Services.Base
|
||||
cache.Remove(key);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Нативные операции Redis, Redis Hash
|
||||
|
||||
public async Task SetHashFieldAsync<T>(string hashKey, string field, T value, TimeSpan? ttl = null)
|
||||
{
|
||||
// меняет одно поле в Hash
|
||||
|
||||
var jsonData = JsonSerializer.Serialize(value);
|
||||
|
||||
// true - поля не было, создалось новое. false - поле было, обновили значение
|
||||
var result = await redis.HashSetAsync(hashKey, field, jsonData);
|
||||
|
||||
// если указан ttl, обновим для всего Hash
|
||||
// если не указан и ранее был создан hashKey, оставит его ttl; а если hashKey не было, то создаст его БЕССРОЧНЫМ!!!
|
||||
if (ttl.HasValue)
|
||||
await SetHashTtlAsync(hashKey, ttl.Value);
|
||||
}
|
||||
|
||||
public async Task<T?> GetHashFieldAsync<T>(string hashKey, string field)
|
||||
{
|
||||
// получить значение поля из Hash
|
||||
var value = await redis.HashGetAsync(hashKey, field);
|
||||
|
||||
if (value.IsNullOrEmpty)
|
||||
return default;
|
||||
|
||||
return JsonSerializer.Deserialize<T>(value);
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, T>> GetAllHashFieldsAsync<T>(string hashKey)
|
||||
{
|
||||
// получить все записи из Hash
|
||||
var objs = await redis.HashGetAllAsync(hashKey);
|
||||
|
||||
if (objs.Length == 0)
|
||||
return new Dictionary<string, T>();
|
||||
|
||||
var result = objs.ToDictionary(
|
||||
t => t.Name.ToString(),
|
||||
t => JsonSerializer.Deserialize<T>(t.Value)
|
||||
);
|
||||
|
||||
return result!;
|
||||
}
|
||||
|
||||
public async Task DeleteHashFieldAsync(string hashKey, string field)
|
||||
{
|
||||
// удалить запись из Hash
|
||||
await redis.HashDeleteAsync(hashKey, field);
|
||||
}
|
||||
|
||||
public async Task<bool> HashFieldExistsAsync(string hashKey, string field)
|
||||
{
|
||||
// есть ли запись в Hash
|
||||
return await redis.HashExistsAsync(hashKey, field);
|
||||
}
|
||||
|
||||
public async Task DeleteHashAsync(string hashKey)
|
||||
{
|
||||
// удалить весь Hash
|
||||
await redis.KeyDeleteAsync(hashKey);
|
||||
}
|
||||
|
||||
public async Task<long> GetHashLengthAsync(string hashKey)
|
||||
{
|
||||
// кол-во записей в hash
|
||||
return await redis.HashLengthAsync(hashKey);
|
||||
}
|
||||
|
||||
public async Task SetHashTtlAsync(string hashKey, TimeSpan ttl)
|
||||
{
|
||||
// Установить ttl для Hash
|
||||
await redis.KeyExpireAsync(hashKey, ttl);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helpers
|
||||
|
||||
public string GetKey(string[] keyParts, string[]? keyPartsToHash = null)
|
||||
{
|
||||
@@ -99,5 +187,7 @@ namespace PARR.DAL.Cache.Services.Base
|
||||
return keyStr.ToLower();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using PARR.DAL.Extensions;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Models.Job;
|
||||
using PARR.DAL.Models.Schedule;
|
||||
using PARR.DAL.Models.TaskModels;
|
||||
using PARR.DAL.Models.Unit;
|
||||
|
||||
namespace PARR.DAL.Context
|
||||
@@ -117,6 +118,15 @@ namespace PARR.DAL.Context
|
||||
|
||||
#endregion
|
||||
|
||||
#region Tasks
|
||||
|
||||
public DbSet<TaskItem> Tasks { get; set; }
|
||||
public DbSet<Models.TaskModels.TaskStatus> TaskStatus { get; set; }
|
||||
public DbSet<TaskType> TaskTypes { get; set; }
|
||||
public DbSet<TaskError> TaskErrors { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
@@ -555,6 +565,35 @@ namespace PARR.DAL.Context
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region TaskType
|
||||
|
||||
modelBuilder.Entity<TaskType>(f =>
|
||||
{
|
||||
f.HasData(new TaskType[]
|
||||
{
|
||||
new() { Code = TaskTypeEnum.Workload, Name = TaskTypeEnum.Workload.ToString(), Description = "Формирование данных для отчетности - Загруженность", MaxRetries = 2, IsSingleton=true, MaxExecutionTimeMinutes=30, RetentionDays=90 }
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
#endregion
|
||||
|
||||
#region TaskStatus
|
||||
|
||||
modelBuilder.Entity<PARR.DAL.Models.TaskModels.TaskStatus>(f =>
|
||||
{
|
||||
f.HasData(new PARR.DAL.Models.TaskModels.TaskStatus[]
|
||||
{
|
||||
new(){Code=TaskItemStatusEnum.Pending, Name=TaskItemStatusEnum.Pending.ToString(), Description="Ожидание"},
|
||||
new(){Code=TaskItemStatusEnum.Processing, Name=TaskItemStatusEnum.Processing.ToString(), Description="В работе"},
|
||||
new(){Code=TaskItemStatusEnum.Success, Name=TaskItemStatusEnum.Success.ToString(), Description="Выполнено успешно"},
|
||||
new(){Code=TaskItemStatusEnum.Failed, Name=TaskItemStatusEnum.Failed.ToString(), Description="Ошибка"}
|
||||
});
|
||||
});
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
//protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
|
||||
@@ -18,5 +18,11 @@
|
||||
/// Расписание регламентных работ
|
||||
/// </summary>
|
||||
public const string Schedule = "schedule";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Управление очередями
|
||||
/// </summary>
|
||||
public const string Task = "task";
|
||||
}
|
||||
}
|
||||
|
||||
30
PARR.DAL/Contracts/TaskItemStatusEnum.cs
Normal file
30
PARR.DAL/Contracts/TaskItemStatusEnum.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
namespace PARR.DAL.Contracts
|
||||
{
|
||||
// TODO: Сначала надо переименовать TaskStatusEnum -> RobotTaskStatusEnum, а потом TaskTaskStatusEnum -> TaskStatusEnum
|
||||
|
||||
/// <summary>
|
||||
/// Статус задач Task
|
||||
/// </summary>
|
||||
public enum TaskItemStatusEnum
|
||||
{
|
||||
/// <summary>
|
||||
/// Ожидание
|
||||
/// </summary>
|
||||
Pending=0,
|
||||
|
||||
/// <summary>
|
||||
/// В работе
|
||||
/// </summary>
|
||||
Processing = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Выполнено успешно
|
||||
/// </summary>
|
||||
Success = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Ошибка
|
||||
/// </summary>
|
||||
Failed = 3
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
namespace PARR.DAL.Contracts
|
||||
{
|
||||
//TODO: Надо это переименовать в RobotTaskStatusEnum
|
||||
|
||||
/// <summary>
|
||||
/// Статус задания на синхронизацию
|
||||
/// </summary>
|
||||
|
||||
13
PARR.DAL/Contracts/TaskTypeEnum.cs
Normal file
13
PARR.DAL/Contracts/TaskTypeEnum.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace PARR.DAL.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Типы заданий
|
||||
/// </summary>
|
||||
public enum TaskTypeEnum
|
||||
{
|
||||
/// <summary>
|
||||
/// Загруженность
|
||||
/// </summary>
|
||||
Workload = 0,
|
||||
}
|
||||
}
|
||||
4383
PARR.DAL/Migrations/20260323035500_tblTasks.Designer.cs
generated
Normal file
4383
PARR.DAL/Migrations/20260323035500_tblTasks.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
172
PARR.DAL/Migrations/20260323035500_tblTasks.cs
Normal file
172
PARR.DAL/Migrations/20260323035500_tblTasks.cs
Normal file
@@ -0,0 +1,172 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
|
||||
|
||||
namespace PARR.DAL.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class tblTasks : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.EnsureSchema(
|
||||
name: "task");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Statuses",
|
||||
schema: "task",
|
||||
columns: table => new
|
||||
{
|
||||
Code = table.Column<int>(type: "integer", nullable: false),
|
||||
Name = table.Column<string>(type: "text", nullable: false),
|
||||
Description = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Statuses", x => x.Code);
|
||||
},
|
||||
comment: "Таблица статусов заданий");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Types",
|
||||
schema: "task",
|
||||
columns: table => new
|
||||
{
|
||||
Code = table.Column<int>(type: "integer", nullable: false),
|
||||
Name = table.Column<string>(type: "text", nullable: false),
|
||||
Description = table.Column<string>(type: "text", nullable: false),
|
||||
MaxRetries = table.Column<int>(type: "integer", nullable: false),
|
||||
MaxExecutionTimeMinutes = table.Column<int>(type: "integer", nullable: false),
|
||||
IsSingleton = table.Column<bool>(type: "boolean", nullable: false),
|
||||
RetentionDays = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Types", x => x.Code);
|
||||
},
|
||||
comment: "Таблица типов заданий");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Tasks",
|
||||
schema: "task",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
DateCreated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
DateModified = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
||||
TypeCode = table.Column<int>(type: "integer", nullable: false),
|
||||
StatusCode = table.Column<int>(type: "integer", nullable: false),
|
||||
Payload = table.Column<string>(type: "text", nullable: true),
|
||||
RetryCount = table.Column<int>(type: "integer", nullable: false),
|
||||
ProcessedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
||||
InitiatorIp = table.Column<string>(type: "text", nullable: true),
|
||||
InitiatorParrComponentId = table.Column<int>(type: "integer", nullable: true),
|
||||
InitiatorComment = table.Column<string>(type: "text", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Tasks", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Tasks_Statuses_StatusCode",
|
||||
column: x => x.StatusCode,
|
||||
principalSchema: "task",
|
||||
principalTable: "Statuses",
|
||||
principalColumn: "Code",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_Tasks_Types_TypeCode",
|
||||
column: x => x.TypeCode,
|
||||
principalSchema: "task",
|
||||
principalTable: "Types",
|
||||
principalColumn: "Code",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
},
|
||||
comment: "Таблица заданий");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Errors",
|
||||
schema: "task",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
DateCreated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
TaskId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
AttemptNumber = table.Column<int>(type: "integer", nullable: false),
|
||||
ErrorMessage = table.Column<string>(type: "text", nullable: false),
|
||||
StackTrace = table.Column<string>(type: "text", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Errors", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Errors_Tasks_TaskId",
|
||||
column: x => x.TaskId,
|
||||
principalSchema: "task",
|
||||
principalTable: "Tasks",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
},
|
||||
comment: "Таблица ошибок заданий");
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
schema: "task",
|
||||
table: "Statuses",
|
||||
columns: new[] { "Code", "Description", "Name" },
|
||||
values: new object[,]
|
||||
{
|
||||
{ 0, "Ожидание", "Pending" },
|
||||
{ 1, "В работе", "Processing" },
|
||||
{ 2, "Выполнено успешно", "Success" },
|
||||
{ 3, "Ошибка", "Failed" }
|
||||
});
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
schema: "task",
|
||||
table: "Types",
|
||||
columns: new[] { "Code", "Description", "IsSingleton", "MaxExecutionTimeMinutes", "MaxRetries", "Name", "RetentionDays" },
|
||||
values: new object[] { 0, "Формирование данных для отчетности - Загруженность", true, 30, 2, "Workload", 90 });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Errors_TaskId",
|
||||
schema: "task",
|
||||
table: "Errors",
|
||||
column: "TaskId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Tasks_StatusCode",
|
||||
schema: "task",
|
||||
table: "Tasks",
|
||||
column: "StatusCode");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Tasks_TypeCode",
|
||||
schema: "task",
|
||||
table: "Tasks",
|
||||
column: "TypeCode");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Errors",
|
||||
schema: "task");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Tasks",
|
||||
schema: "task");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Statuses",
|
||||
schema: "task");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Types",
|
||||
schema: "task");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2751,6 +2751,178 @@ namespace PARR.DAL.Migrations
|
||||
b.ToTable("Subprocesses");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.TaskModels.TaskError", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<int>("AttemptNumber")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTimeOffset>("DateCreated")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("ErrorMessage")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("StackTrace")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Guid>("TaskId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("TaskId");
|
||||
|
||||
b.ToTable("Errors", "task", t =>
|
||||
{
|
||||
t.HasComment("Таблица ошибок заданий");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.TaskModels.TaskItem", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("DateCreated")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTimeOffset?>("DateModified")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("InitiatorComment")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("InitiatorIp")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int?>("InitiatorParrComponentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Payload")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTimeOffset?>("ProcessedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("RetryCount")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("StatusCode")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("TypeCode")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("StatusCode");
|
||||
|
||||
b.HasIndex("TypeCode");
|
||||
|
||||
b.ToTable("Tasks", "task", t =>
|
||||
{
|
||||
t.HasComment("Таблица заданий");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.TaskModels.TaskStatus", b =>
|
||||
{
|
||||
b.Property<int>("Code")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Code");
|
||||
|
||||
b.ToTable("Statuses", "task", t =>
|
||||
{
|
||||
t.HasComment("Таблица статусов заданий");
|
||||
});
|
||||
|
||||
b.HasData(
|
||||
new
|
||||
{
|
||||
Code = 0,
|
||||
Description = "Ожидание",
|
||||
Name = "Pending"
|
||||
},
|
||||
new
|
||||
{
|
||||
Code = 1,
|
||||
Description = "В работе",
|
||||
Name = "Processing"
|
||||
},
|
||||
new
|
||||
{
|
||||
Code = 2,
|
||||
Description = "Выполнено успешно",
|
||||
Name = "Success"
|
||||
},
|
||||
new
|
||||
{
|
||||
Code = 3,
|
||||
Description = "Ошибка",
|
||||
Name = "Failed"
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.TaskModels.TaskType", b =>
|
||||
{
|
||||
b.Property<int>("Code")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsSingleton")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int>("MaxExecutionTimeMinutes")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("MaxRetries")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("RetentionDays")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Code");
|
||||
|
||||
b.ToTable("Types", "task", t =>
|
||||
{
|
||||
t.HasComment("Таблица типов заданий");
|
||||
});
|
||||
|
||||
b.HasData(
|
||||
new
|
||||
{
|
||||
Code = 0,
|
||||
Description = "Формирование данных для отчетности - Загруженность",
|
||||
IsSingleton = true,
|
||||
MaxExecutionTimeMinutes = 30,
|
||||
MaxRetries = 2,
|
||||
Name = "Workload",
|
||||
RetentionDays = 90
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.TaskStatus", b =>
|
||||
{
|
||||
b.Property<int>("Code")
|
||||
@@ -3715,6 +3887,36 @@ namespace PARR.DAL.Migrations
|
||||
b.Navigation("Process");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.TaskModels.TaskError", b =>
|
||||
{
|
||||
b.HasOne("PARR.DAL.Models.TaskModels.TaskItem", "TaskItem")
|
||||
.WithMany("TaskErrors")
|
||||
.HasForeignKey("TaskId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("TaskItem");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.TaskModels.TaskItem", b =>
|
||||
{
|
||||
b.HasOne("PARR.DAL.Models.TaskModels.TaskStatus", "TaskStatus")
|
||||
.WithMany("Tasks")
|
||||
.HasForeignKey("StatusCode")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("PARR.DAL.Models.TaskModels.TaskType", "TaskType")
|
||||
.WithMany("Tasks")
|
||||
.HasForeignKey("TypeCode")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("TaskStatus");
|
||||
|
||||
b.Navigation("TaskType");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.Template", b =>
|
||||
{
|
||||
b.HasOne("PARR.DAL.Models.Job.Job", "Job")
|
||||
@@ -4077,6 +4279,21 @@ namespace PARR.DAL.Migrations
|
||||
b.Navigation("Tnks");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.TaskModels.TaskItem", b =>
|
||||
{
|
||||
b.Navigation("TaskErrors");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.TaskModels.TaskStatus", b =>
|
||||
{
|
||||
b.Navigation("Tasks");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.TaskModels.TaskType", b =>
|
||||
{
|
||||
b.Navigation("Tasks");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.TaskStatus", b =>
|
||||
{
|
||||
b.Navigation("RobotConfigurations");
|
||||
|
||||
32
PARR.DAL/Models/TaskModels/TaskError.cs
Normal file
32
PARR.DAL/Models/TaskModels/TaskError.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.DAL.Context;
|
||||
using PARR.DAL.Models.Base;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace PARR.DAL.Models.TaskModels
|
||||
{
|
||||
[Table("Errors", Schema = DataContextSettings.Task)]
|
||||
[Comment("Таблица ошибок заданий")]
|
||||
public class TaskError : IBase
|
||||
{
|
||||
[Key]
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public DateTimeOffset DateCreated { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public DateTimeOffset? DateModified { get; set; }
|
||||
|
||||
public Guid TaskId { get; set; }
|
||||
|
||||
public int AttemptNumber { get; set; }
|
||||
|
||||
public required string ErrorMessage { get; set; }
|
||||
|
||||
public string? StackTrace { get; set; }
|
||||
|
||||
[ForeignKey(nameof(TaskId))]
|
||||
public TaskItem? TaskItem { get; set; }
|
||||
}
|
||||
}
|
||||
53
PARR.DAL/Models/TaskModels/TaskItem.cs
Normal file
53
PARR.DAL/Models/TaskModels/TaskItem.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.Common.Domain;
|
||||
using PARR.Constants;
|
||||
using PARR.DAL.Context;
|
||||
using PARR.DAL.Contracts;
|
||||
using PARR.DAL.Models.Base;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace PARR.DAL.Models.TaskModels
|
||||
{
|
||||
[Table("Tasks", Schema = DataContextSettings.Task)]
|
||||
[Comment("Таблица заданий")]
|
||||
public class TaskItem : IBase, IHistoryInitiator
|
||||
{
|
||||
[Key]
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public DateTimeOffset DateCreated { get; set; }
|
||||
|
||||
public DateTimeOffset? DateModified { get; set; }
|
||||
|
||||
public TaskTypeEnum TypeCode { get; set; }
|
||||
|
||||
public TaskItemStatusEnum StatusCode { get; set; }
|
||||
|
||||
public string? Payload { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Кол-во попыток
|
||||
/// </summary>
|
||||
public int RetryCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Дата завершения (устанавливается или когда Успех или когда Ошибка)
|
||||
/// </summary>
|
||||
public DateTimeOffset? ProcessedAt { get; set; }
|
||||
|
||||
|
||||
public string? InitiatorIp { get; set; }
|
||||
public ParrComponentsEnum? InitiatorParrComponentId { get; set; }
|
||||
public string? InitiatorComment { get; set; }
|
||||
|
||||
|
||||
[ForeignKey(nameof(TypeCode))]
|
||||
public TaskType? TaskType { get; set; }
|
||||
|
||||
[ForeignKey(nameof(StatusCode))]
|
||||
public TaskStatus? TaskStatus { get; set; }
|
||||
|
||||
public ICollection<TaskError> TaskErrors { get; set; } = new HashSet<TaskError>();
|
||||
}
|
||||
}
|
||||
23
PARR.DAL/Models/TaskModels/TaskStatus.cs
Normal file
23
PARR.DAL/Models/TaskModels/TaskStatus.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.DAL.Context;
|
||||
using PARR.DAL.Contracts;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace PARR.DAL.Models.TaskModels
|
||||
{
|
||||
[Table("Statuses", Schema = DataContextSettings.Task)]
|
||||
[Comment("Таблица статусов заданий")]
|
||||
public class TaskStatus
|
||||
{
|
||||
[Key]
|
||||
public TaskItemStatusEnum Code { get; set; }
|
||||
|
||||
public required string Name { get; set; }
|
||||
|
||||
public required string Description { get; set; }
|
||||
|
||||
|
||||
public ICollection<TaskItem> Tasks { get; set; } = new HashSet<TaskItem>();
|
||||
}
|
||||
}
|
||||
43
PARR.DAL/Models/TaskModels/TaskType.cs
Normal file
43
PARR.DAL/Models/TaskModels/TaskType.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.DAL.Context;
|
||||
using PARR.DAL.Contracts;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace PARR.DAL.Models.TaskModels
|
||||
{
|
||||
[Table("Types", Schema = DataContextSettings.Task)]
|
||||
[Comment("Таблица типов заданий")]
|
||||
public class TaskType
|
||||
{
|
||||
[Key]
|
||||
public TaskTypeEnum Code { get; set; }
|
||||
|
||||
public required string Name { get; set; }
|
||||
|
||||
public required string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Максимальное кол-во попыток
|
||||
/// </summary>
|
||||
public int MaxRetries { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Максимальное время выполнения
|
||||
/// </summary>
|
||||
public int MaxExecutionTimeMinutes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Одновременно может быть только одна задача или несколько
|
||||
/// </summary>
|
||||
public bool IsSingleton { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Сколько дней хранить в БД
|
||||
/// </summary>
|
||||
public int RetentionDays { get; set; }
|
||||
|
||||
|
||||
public ICollection<TaskItem> Tasks { get; set; } = new HashSet<TaskItem>();
|
||||
}
|
||||
}
|
||||
@@ -18,12 +18,15 @@ using PARR.DAL.Services.Implementation;
|
||||
using PARR.DAL.Services.Implementations;
|
||||
using PARR.DAL.Services.Implementations.Job;
|
||||
using PARR.DAL.Services.Implementations.Schedule;
|
||||
using PARR.DAL.Services.Implementations.TaskServices;
|
||||
using PARR.DAL.Services.Implementations.Unit;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
using PARR.DAL.Services.Interfaces.Job;
|
||||
using PARR.DAL.Services.Interfaces.Schedule;
|
||||
using PARR.DAL.Services.Interfaces.TaskServices;
|
||||
using PARR.DAL.Services.Interfaces.Unit;
|
||||
using PARR.DAL.Settings;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace PARR.DAL
|
||||
{
|
||||
@@ -45,16 +48,24 @@ namespace PARR.DAL
|
||||
|
||||
#region Redis + cache services
|
||||
|
||||
services.AddSingleton<IConnectionMultiplexer>(sp =>
|
||||
{
|
||||
// IConnectionMultiplexer - для нативных операций Redis
|
||||
var connectionString = configuration.GetConnectionString("RedisConnection");
|
||||
return ConnectionMultiplexer.Connect(connectionString);
|
||||
});
|
||||
|
||||
services.AddStackExchangeRedisCache(opt =>
|
||||
{
|
||||
opt.Configuration = configuration.GetConnectionString("RedisConnection");
|
||||
});
|
||||
|
||||
|
||||
var groupedShortcodesCacheSettings = new GroupedShortcodesCacheSettings();
|
||||
configuration.GetSection(nameof(GroupedShortcodesCacheSettings)).Bind(groupedShortcodesCacheSettings);
|
||||
services.AddSingleton(groupedShortcodesCacheSettings);
|
||||
|
||||
services.AddTransient<IRedisCacheService, RedisCacheService>();
|
||||
services.AddSingleton<IRedisCacheService, RedisCacheService>();
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -135,6 +146,13 @@ namespace PARR.DAL
|
||||
|
||||
#endregion
|
||||
|
||||
#region Task
|
||||
|
||||
services.AddTransient<ITaskErrorService, TaskErrorService>();
|
||||
services.AddTransient<ITaskService, TaskService>();
|
||||
|
||||
#endregion
|
||||
|
||||
//services.AddTransient<INextRunModifierService, NextRunModifierService>();
|
||||
|
||||
#region NextRun Services
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PARR.DAL.Context;
|
||||
using PARR.DAL.Models.TaskModels;
|
||||
using PARR.DAL.Services.Abstracts;
|
||||
using PARR.DAL.Services.Interfaces.TaskServices;
|
||||
|
||||
namespace PARR.DAL.Services.Implementations.TaskServices
|
||||
{
|
||||
internal class TaskErrorService : BaseService<TaskError>, ITaskErrorService
|
||||
{
|
||||
private readonly DataContext dataContext;
|
||||
|
||||
protected override DbSet<TaskError> EntitySet => dataContext.TaskErrors;
|
||||
|
||||
protected override DataContext EntitiContext => dataContext;
|
||||
|
||||
public TaskErrorService(DataContext dataContext, ILogger<TaskErrorService> logger): base(logger)
|
||||
{
|
||||
this.dataContext = dataContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PARR.DAL.Context;
|
||||
using PARR.DAL.Models.TaskModels;
|
||||
using PARR.DAL.Services.Abstracts;
|
||||
using PARR.DAL.Services.Interfaces.TaskServices;
|
||||
|
||||
namespace PARR.DAL.Services.Implementations.TaskServices
|
||||
{
|
||||
internal class TaskService : BaseService<TaskItem>, ITaskService
|
||||
{
|
||||
private readonly DataContext dataContext;
|
||||
|
||||
protected override DbSet<TaskItem> EntitySet => dataContext.Tasks;
|
||||
|
||||
protected override DataContext EntitiContext => dataContext;
|
||||
|
||||
public TaskService(DataContext dataContext, ILogger<TaskService> logger) : base(logger)
|
||||
{
|
||||
this.dataContext = dataContext;
|
||||
}
|
||||
|
||||
|
||||
// метод атомарного взятия в работу
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using PARR.DAL.Models.TaskModels;
|
||||
using PARR.DAL.Services.Interfaces.Base;
|
||||
|
||||
namespace PARR.DAL.Services.Interfaces.TaskServices
|
||||
{
|
||||
public interface ITaskErrorService : IBaseService<TaskError>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using PARR.DAL.Models.TaskModels;
|
||||
using PARR.DAL.Services.Interfaces.Base;
|
||||
|
||||
namespace PARR.DAL.Services.Interfaces.TaskServices
|
||||
{
|
||||
public interface ITaskService : IBaseService<TaskItem>
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user