Refactor config loading to async MediatR query in job

Switched FinalizeDocumentJob to use MediatR for async config retrieval, replacing direct model access. Updated _config type to ConfigDto?, injected IMediator, and removed obsolete DbConfig references. Cleaned up ExecuteAsync method for improved clarity and decoupling.
This commit is contained in:
2026-03-06 13:58:16 +01:00
parent d6058c41d0
commit f3ae8a9c49
2 changed files with 7 additions and 7 deletions

View File

@@ -8,15 +8,18 @@ using GdPicture14;
using Microsoft.Data.SqlClient; using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using EnvelopeGenerator.ServiceHost.Extensions; using EnvelopeGenerator.ServiceHost.Extensions;
using MediatR;
using EnvelopeGenerator.Application.Configuration.Queries;
using EnvelopeGenerator.Application.Common.Dto;
namespace EnvelopeGenerator.ServiceHost.Jobs; namespace EnvelopeGenerator.ServiceHost.Jobs;
[Obsolete("ActionService is a placeholder service added by copilot. Migrate the actual logic from CommonServices.Jobs")] [Obsolete("ActionService is a placeholder service added by copilot. Migrate the actual logic from CommonServices.Jobs")]
public class FinalizeDocumentJob(IOptions<WorkerOptions> options, IConfiguration config, ILogger<FinalizeDocumentJob> logger, TempFiles tempFiles, ActionService actionService, PDFBurner pdfBurner, PDFMerger pdfMerger, ReportCreator reportCreator, ConfigModel _configModel, EnvelopeModel _envelopeModel, ReportModel _reportModel, MSSQLServer _database, GdViewer? _gdViewer, LicenseManager licenseManager) public class FinalizeDocumentJob(IOptions<WorkerOptions> options, IConfiguration config, ILogger<FinalizeDocumentJob> logger, TempFiles tempFiles, ActionService actionService, PDFBurner pdfBurner, PDFMerger pdfMerger, ReportCreator reportCreator, EnvelopeModel _envelopeModel, ReportModel _reportModel, MSSQLServer _database, GdViewer? _gdViewer, LicenseManager licenseManager, IMediator mediator)
{ {
private readonly WorkerOptions _options = options.Value; private readonly WorkerOptions _options = options.Value;
private DbConfig? _config; private ConfigDto? _config;
private const int CompleteWaitTime = 1; private const int CompleteWaitTime = 1;
private string _parentFolderUid = string.Empty; private string _parentFolderUid = string.Empty;
@@ -30,7 +33,7 @@ public class FinalizeDocumentJob(IOptions<WorkerOptions> options, IConfiguration
public byte[]? DocAsByte { get; set; } public byte[]? DocAsByte { get; set; }
} }
public Task ExecuteAsync(CancellationToken cancellationToken = default) public async Task ExecuteAsync(CancellationToken cancel = default)
{ {
var gdPictureKey = _options.GdPictureLicenseKey; var gdPictureKey = _options.GdPictureLicenseKey;
tempFiles.Create(); tempFiles.Create();
@@ -40,7 +43,7 @@ public class FinalizeDocumentJob(IOptions<WorkerOptions> options, IConfiguration
try try
{ {
logger.LogDebug("Loading Configuration.."); logger.LogDebug("Loading Configuration..");
_config = _configModel?.LoadConfiguration() ?? throw new InvalidOperationException("Configuration could not be loaded because there is no record"); _config = await mediator.Send(new ReadDefaultConfigQuery(), cancel);
logger.LogDebug("DocumentPath: [{documentPath}]", _config.DocumentPath); logger.LogDebug("DocumentPath: [{documentPath}]", _config.DocumentPath);
logger.LogDebug("ExportPath: [{exportPath}]", _config.ExportPath); logger.LogDebug("ExportPath: [{exportPath}]", _config.ExportPath);
@@ -174,8 +177,6 @@ public class FinalizeDocumentJob(IOptions<WorkerOptions> options, IConfiguration
{ {
logger.LogDebug("Job execution for [{jobId}] ended", jobId); logger.LogDebug("Job execution for [{jobId}] ended", jobId);
} }
return Task.FromResult(true);
} }
private void UpdateFileDb(string filePath, long envelopeId) private void UpdateFileDb(string filePath, long envelopeId)

View File

@@ -9,6 +9,5 @@ public class State
public int UserId { get; set; } public int UserId { get; set; }
public FormUser? User { get; set; } public FormUser? User { get; set; }
public Config? Config { get; set; } public Config? Config { get; set; }
public DbConfig? DbConfig { get; set; }
public MSSQLServer? Database { get; set; } public MSSQLServer? Database { get; set; }
} }