reafctor(templateMatcher): сервис синхронизации неактуальных шаблонов вынесен в отдельный класс

This commit is contained in:
Mikhail Kuznetsov
2026-09-10 14:12:47 +10:00
parent 83c6a5f605
commit 0629579cf0
12 changed files with 477 additions and 376 deletions

View File

@@ -3,6 +3,7 @@ using PARR.Core.Services.MatchingStatusService;
using PARR.Domain.Cache.Models;
using PARR.Domain.Entities.Base.History;
using PARR.Domain.Enums;
using PARR.TemplateMatcher.Exceptions;
using PARR.TemplateMatcher.Services.GroupedSync;
using PARR.TemplateMatcher.Services.Implementations.GroupedSync;
using PARR.TemplateMatcher.Services.Interfaces;
@@ -17,6 +18,7 @@ internal class GroupedTemplateSynchronizer : ITemplateSynchronizer
private readonly IMatchingStatusService _matchingStatusService;
private readonly ILogger<GroupedTemplateSynchronizer> _logger;
public GroupedTemplateSynchronizer(
IEnumerable<IGroupedSyncStage> readStages,
IEnumerable<IGroupedSyncWriteStage> writeStages,
@@ -30,7 +32,8 @@ internal class GroupedTemplateSynchronizer : ITemplateSynchronizer
_logger = logger;
}
public async Task SyncTemplatesForJobGroupAsync(Guid jobGroupId, HistoryInitiator initiator, bool dryRun = false)
public async Task SyncTemplatesForJobGroupAsync(Guid jobGroupId, HistoryInitiator initiator, bool dryRun = false, CancellationToken ct = default)
{
_logger.LogInformation("Начало синхронизации шаблонов для JobGroup {JobGroupId} (DryRun={DryRun})", jobGroupId, dryRun);
@@ -93,7 +96,7 @@ internal class GroupedTemplateSynchronizer : ITemplateSynchronizer
_logger.LogInformation("[Perf] JobGroup '{JobGroupName}' ({JobGroupId}) | ИТОГО: {TotalMs} мс",
context.JobGroupName, jobGroupId, totalSw.ElapsedMilliseconds);
}
catch (GroupedSyncEarlyExitException ex)
catch (SyncEarlyExitException ex)
{
totalSw.Stop();
_logger.LogInformation("JobGroup {JobGroupId}: {Reason} ({ElapsedMs} мс)",
@@ -111,6 +114,7 @@ internal class GroupedTemplateSynchronizer : ITemplateSynchronizer
}
}
private void PrintDryRunReport(GroupedSyncContext context)
{
_logger.LogInformation("========== [DryRun] ОТЧЁТ по JobGroup '{JobGroupName}' ({JobGroupId}) ==========",
@@ -140,7 +144,7 @@ internal class GroupedTemplateSynchronizer : ITemplateSynchronizer
foreach (var entry in subGroup.Entries)
{
_logger.LogInformation(
_logger.LogDebug(
"[DryRun] - {Unit} (ValueId: {ValueId})",
context.FormatUnit(entry.UnitId),
entry.UnitFieldValueId);
@@ -157,18 +161,21 @@ internal class GroupedTemplateSynchronizer : ITemplateSynchronizer
_logger.LogInformation("========== [DryRun] КОНЕЦ ОТЧЁТА ==========");
}
public Task SyncTemplatesForJobAsync(Guid jobId, HistoryInitiator initiator)
public Task SyncTemplatesForJobAsync(Guid jobId, HistoryInitiator initiator, bool dryRun = false, CancellationToken ct = default)
{
_logger.LogWarning("GroupedTemplateSynchronizer: SyncTemplatesForJob вызван для JobId {JobId}. Это не поддерживаемая операция.", jobId);
return Task.CompletedTask;
}
public Task UpdateTemplatesForJobAsync(Guid jobId, HistoryInitiator initiator)
public Task UpdateTemplatesForJobAsync(Guid jobId, HistoryInitiator initiator, CancellationToken ct = default)
{
_logger.LogWarning("GroupedTemplateSynchronizer: UpdateTemplatesForJob вызван для JobId {JobId}. Это не поддерживаемая операция.", jobId);
return Task.CompletedTask;
}
private async Task SetStatusAsync(Guid jobGroupId, string comment)
{
var status = new MatchingStatusItemDto