feat(dal,api): IMatchingStatusService - управление статусами matcher`a. Отображение статусов в АПИ, нельзя повторно из апи отправить задание мэтчеру если сейчас идет matching

This commit is contained in:
Mikhail Trubnikov
2026-01-16 11:04:26 +10:00
parent 3205c1db8e
commit 99a491ede8
14 changed files with 303 additions and 91 deletions

View File

@@ -6,9 +6,9 @@ namespace PARR.DAL.Cache.Models
/// <summary>
/// КЭШ модель, состояние matching`a
/// </summary>
public class MatchingStatus : IBaseCache<MatchingStatusDto>
public class MatchingStatusItem : IBaseCache<MatchingStatusItemDto>
{
public required MatchingStatusDto Data { get; set; }
public required MatchingStatusItemDto Data { get; set; }
public DateTimeOffset Timestamp { get; set; }
@@ -16,7 +16,7 @@ namespace PARR.DAL.Cache.Models
}
public class MatchingStatusDto
public class MatchingStatusItemDto
{
public DateTimeOffset DateStart { get; set; }

View File

@@ -1,63 +0,0 @@
using PARR.Constants;
using PARR.DAL.Cache.Models;
using PARR.DAL.Cache.Services.Base;
namespace PARR.DAL.Cache.Services
{
internal class CacheMatchingStatusService : ICacheMatchingStatusService
{
private readonly IRedisCacheService redisCacheService;
public CacheMatchingStatusService(IRedisCacheService redisCacheService)
{
this.redisCacheService = redisCacheService;
}
public async Task DeleteCacheAsync(Guid id, SyncTaskEntityTypeEnum type)
{
var key = GetKey(id, type);
await redisCacheService.DeleteCachedDataAsync(key);
}
public async Task<MatchingStatus?> GetDataAsync(Guid id, SyncTaskEntityTypeEnum type)
{
var key = GetKey(id, type);
return await redisCacheService.GetCachedDataAsync<MatchingStatus>(key);
}
public async Task SetCacheAsync(Guid id, SyncTaskEntityTypeEnum type, MatchingStatusDto data, TimeSpan cacheDuration)
{
var key = GetKey(id, type);
await redisCacheService.SetCachedDataAsync(key, data, cacheDuration);
}
private string GetKey(Guid id, SyncTaskEntityTypeEnum type)
{
var typeStr = "";
switch (type)
{
case SyncTaskEntityTypeEnum.Job:
typeStr = "j";
break;
case SyncTaskEntityTypeEnum.JobGroup:
typeStr = "g";
break;
case SyncTaskEntityTypeEnum.Template:
typeStr = "t";
break;
default:
break;
}
return redisCacheService.GetKey(new string[] { "ms", typeStr, id.ToString() });
}
}
}

View File

@@ -1,18 +0,0 @@
using PARR.Constants;
using PARR.DAL.Cache.Models;
namespace PARR.DAL.Cache.Services
{
/// <summary>
/// Сервис - статус matching`a
/// </summary>
public interface ICacheMatchingStatusService
{
Task<MatchingStatus?> GetDataAsync(Guid id, SyncTaskEntityTypeEnum type);
Task SetCacheAsync(Guid id, SyncTaskEntityTypeEnum type, MatchingStatusDto data, TimeSpan cacheDuration);
Task DeleteCacheAsync(Guid id, SyncTaskEntityTypeEnum type);
}
}