refactor(templateMatcher): Переход на Pipeline-архитектуру для SimpleSync и GroupedSync.
- SimpleTemplateSynchronizer и GroupedTemplateSynchronizer переведены на паттерн Pipeline с разделением на Read/Write этапы - Выделены контракты этапов (ISimpleSyncStage, IGroupedSyncStage) и контексты (SimpleSyncContext, GroupedSyncContext) - Read-этапы безопасны для тестов (не пишут в БД/MQ), Write-этапы изолированы через отдельные интерфейсы - Добавлено [Perf]-логирование каждого этапа с метриками времени выполнения - Логи приведены к человекочитаемому формату 'Имя' (ID) для Job, JobGroup и Unit - Устранено дублирование данных в контекстах (FilteredUnits перезаписывается, TemplateGroups строго типизирован) - Константы неиспользуемых шаблонов вынесены в UnusedTemplateConstants - Структура проекта реорганизована: SimpleSync, GroupedSync, Implementations, Interfaces
This commit is contained in:
@@ -25,4 +25,8 @@
|
||||
<ProjectReference Include="..\PARR.TemplateDistributor\PARR.TemplateDistributor.csproj" />
|
||||
<ProjectReference Include="..\PARR.TemplateMatcher\PARR.TemplateMatcher.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="log\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.Core.Common.Interfaces;
|
||||
using PARR.Core.Repositories.Interfaces.Job;
|
||||
using PARR.Core.Services.UnitFilterService;
|
||||
using PARR.Domain.Cache;
|
||||
using PARR.Domain.Entities.Base.History;
|
||||
using PARR.Domain.Enums;
|
||||
@@ -8,7 +9,11 @@ using PARR.EsppApi;
|
||||
using PARR.EsppApi.Constants;
|
||||
using PARR.EsppApi.Models.Query;
|
||||
using PARR.TemplateMatcher;
|
||||
using PARR.TemplateMatcher.Services.GroupedSync;
|
||||
using PARR.TemplateMatcher.Services.Implementations;
|
||||
using PARR.TemplateMatcher.Services.Interfaces;
|
||||
using PARR.Test.NextRun;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace PARR.Test
|
||||
{
|
||||
@@ -41,7 +46,8 @@ namespace PARR.Test
|
||||
//var bbb = aaa.ToOffset(new TimeSpan(3, 0, 0));
|
||||
|
||||
|
||||
await TemplateMatcherTest();
|
||||
//await TemplateMatcherTest();
|
||||
await PreCommitValidationTest();
|
||||
|
||||
|
||||
|
||||
@@ -161,6 +167,91 @@ namespace PARR.Test
|
||||
#endregion
|
||||
|
||||
}
|
||||
#region PreCommitValidation
|
||||
|
||||
private async Task PreCommitValidationTest()
|
||||
{
|
||||
_logger.LogInformation("=== НАЧАЛО PRE-COMMIT ВАЛИДАЦИИ ===");
|
||||
|
||||
await using var scope = serviceProvider.CreateAsyncScope();
|
||||
|
||||
// === 1. Проверка Simple Pipeline ===
|
||||
_logger.LogInformation("--- Simple Pipeline ---");
|
||||
var simpleSync = scope.ServiceProvider
|
||||
.GetRequiredService<IEnumerable<ITemplateSynchronizer>>()
|
||||
.FirstOrDefault(s => s is SimpleTemplateSynchronizer);
|
||||
|
||||
if (simpleSync == null)
|
||||
{
|
||||
_logger.LogError("[FAIL] SimpleTemplateSynchronizer не найден в DI");
|
||||
return;
|
||||
}
|
||||
|
||||
// Подставьте реальный JobId для Simple
|
||||
var simpleJobId = Guid.Parse("6ff1de05-80c3-4b38-846b-0c793fd7fc8c");
|
||||
|
||||
try
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
await simpleSync.SyncTemplatesForJobAsync(simpleJobId, new HistoryInitiator
|
||||
{
|
||||
InitiatorIp = "127.0.0.1",
|
||||
InitiatorParrComponentId = ParrComponentsEnum.Master,
|
||||
InitiatorComment = "Pre-commit validation: Simple Pipeline"
|
||||
});
|
||||
sw.Stop();
|
||||
_logger.LogInformation("[OK] Simple Pipeline: завершено за {Ms} мс", sw.ElapsedMilliseconds);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "[FAIL] Simple Pipeline: исключение");
|
||||
}
|
||||
|
||||
// === 2. Проверка Grouped Pipeline ===
|
||||
_logger.LogInformation("--- Grouped Pipeline ---");
|
||||
var groupedSync = scope.ServiceProvider
|
||||
.GetRequiredService<IEnumerable<ITemplateSynchronizer>>()
|
||||
.FirstOrDefault(s => s is GroupedTemplateSynchronizer);
|
||||
|
||||
if (groupedSync == null)
|
||||
{
|
||||
_logger.LogError("[FAIL] GroupedTemplateSynchronizer не найден в DI");
|
||||
return;
|
||||
}
|
||||
|
||||
// Подставьте реальный JobGroupId для Grouped
|
||||
var groupedJobGroupId = Guid.Parse("51acaa95-08bf-425f-9a09-87b6a4cbc77e");
|
||||
|
||||
try
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
await groupedSync.SyncTemplatesForJobGroupAsync(groupedJobGroupId, new HistoryInitiator
|
||||
{
|
||||
InitiatorIp = "127.0.0.1",
|
||||
InitiatorParrComponentId = ParrComponentsEnum.Master,
|
||||
InitiatorComment = "Pre-commit validation: Grouped Pipeline"
|
||||
});
|
||||
sw.Stop();
|
||||
_logger.LogInformation("[OK] Grouped Pipeline: завершено за {Ms} мс", sw.ElapsedMilliseconds);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "[FAIL] Grouped Pipeline: исключение");
|
||||
}
|
||||
|
||||
// === 3. Проверка контрактных констант ===
|
||||
_logger.LogInformation("--- Контрактные константы ---");
|
||||
var constantsType = typeof(PARR.TemplateMatcher.Constants.UnusedTemplateConstants);
|
||||
var fields = constantsType.GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
|
||||
|
||||
foreach (var field in fields)
|
||||
{
|
||||
var value = field.GetValue(null);
|
||||
_logger.LogInformation("[OK] Константа {Name} = '{Value}'", field.Name, value);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region TemplateMatcher
|
||||
private async Task TemplateMatcherTest()
|
||||
|
||||
@@ -1,23 +1,30 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"RedisConnection": "10.99.253.216:6379,password=ParrP@ssPtk202MMdevDvs"
|
||||
"ConnectionStrings": {
|
||||
"RedisConnection": "10.99.253.216:6379,password=ParrP@ssPtk202MMdevDvs"
|
||||
},
|
||||
"Serilog": {
|
||||
"MinimumLevel": {
|
||||
"Default": "Debug",
|
||||
"Override": {
|
||||
"Microsoft": "Warning",
|
||||
"PARR.DAL": "Information",
|
||||
"PARR.Infrastructure.Redis": "Information",
|
||||
"PARR.TemplateMatcher.Services.GroupedSync.GroupedTemplateProcessor": "Information"
|
||||
}
|
||||
},
|
||||
"Serilog": {
|
||||
"MinimumLevel": {
|
||||
"Default": "Debug",
|
||||
"Override": {
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Debug"
|
||||
}
|
||||
},
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "log/log-.txt",
|
||||
"rollingInterval": "Day"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "log/log-.txt",
|
||||
"rollingInterval": "Day"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"MqSettings": {
|
||||
"TemplateMatcher": { "HostName": "10.99.253.216" },
|
||||
"TemplateGenerator": { "HostName": "10.99.253.216" },
|
||||
"TemplateUpdater": { "HostName": "10.99.253.216" }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +1,61 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Server=10.99.253.184;Database=parr;User Id=app_parr; Password=PosdfkhT&)%sdfligL&%5546;",
|
||||
"RedisConnection": "parr-redis:6379,password=ParrP@ssPtk202MMdevDvs"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"Serilog": {
|
||||
"MinimumLevel": {
|
||||
"Default": "Information",
|
||||
"Override": {
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "log/log-.txt",
|
||||
"rollingInterval": "Day"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"EsppOrderSettings": {
|
||||
//dev
|
||||
//"Url": "http://rzd-espp-t-rpa-app-1.gvc.oao.rzd:8080/espp_api/OperationExecutor/",
|
||||
"Url": "http://espp.gvc.rzd/esppapi_prom/OperationExecutor/",
|
||||
"UserName": "Auto-PTK-INFO-0002-DVS",
|
||||
"AccountName": "АВТО ТЕХНОЛОГ ПТК-ИНФО-0002-ДВС (AUTO-PTK-INFO-0002-DVS)",
|
||||
"Password": "123456789",
|
||||
"EsppUserTimeZone": 3,
|
||||
"RobotEk": "РПА-РОБИН-ГВЦ-ЕСПП-ТС-513-ДВС",
|
||||
"CodeRRO": "ЦТС-РЦТ-9999"
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Server=10.99.253.184;Database=parr;User Id=app_parr; Password=PosdfkhT&)%sdfligL&%5546;",
|
||||
"RedisConnection": "parr-redis:6379,password=ParrP@ssPtk202MMdevDvs"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"Serilog": {
|
||||
"MinimumLevel": {
|
||||
"Default": "Information",
|
||||
"Override": {
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "log/log-.txt",
|
||||
"rollingInterval": "Day"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"EsppOrderSettings": {
|
||||
//dev
|
||||
//"Url": "http://rzd-espp-t-rpa-app-1.gvc.oao.rzd:8080/espp_api/OperationExecutor/",
|
||||
"Url": "http://espp.gvc.rzd/esppapi_prom/OperationExecutor/",
|
||||
"UserName": "Auto-PTK-INFO-0002-DVS",
|
||||
"AccountName": "АВТО ТЕХНОЛОГ ПТК-ИНФО-0002-ДВС (AUTO-PTK-INFO-0002-DVS)",
|
||||
"Password": "123456789",
|
||||
"EsppUserTimeZone": 3,
|
||||
"RobotEk": "РПА-РОБИН-ГВЦ-ЕСПП-ТС-513-ДВС",
|
||||
"CodeRRO": "ЦТС-РЦТ-9999"
|
||||
},
|
||||
"MqSettings": {
|
||||
"TemplateMatcher": {
|
||||
"HostName": "parr-rabbitmq",
|
||||
"QueueName": "parr-template-matcher",
|
||||
"User": "template_matcher_reader",
|
||||
"Password": "wzqj$Z@3:poasad;lk324@oot"
|
||||
},
|
||||
"TemplateGenerator": {
|
||||
"HostName": "parr-rabbitmq",
|
||||
"QueueName": "parr-template-generator",
|
||||
"User": "template_generator_writer",
|
||||
"Password": "B;6h+yF$zQ0OSkLX"
|
||||
},
|
||||
"TemplateUpdater": {
|
||||
"HostName": "parr-rabbitmq",
|
||||
"QueueName": "parr-template-updater",
|
||||
"User": "template_updater_writer",
|
||||
"Password": "sjdhgfkJHGIUFDi14asd^12"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user