Introduced `RemoteEnvelopeFinalizationTrigger` to enable triggering the envelope finalization worker via a remote HTTP endpoint. Added `BackgroundServicesOptions` for centralized configuration of background services, including enabling/disabling the local worker and configuring the remote trigger URL. Enhanced `TriggerFinalizationWorkerBehavior` with improved error handling and logging using `ILogger`. Added `DisableControllerConvention` to dynamically exclude controllers based on configuration. Updated `Program.cs` for conditional service registration and improved configuration loading. Modified `appsettings.json` and `appsettings.Development.json` to include remote trigger settings. Incremented project version to `2.1.0-beta`. Refactored code for better maintainability, scalability, and observability.
38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using EnvelopeGenerator.Application.Common.Interfaces;
|
|
using EnvelopeGenerator.Application.DocReceiverElements.Commands;
|
|
using MediatR;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace EnvelopeGenerator.Application.DocReceiverElements.Behaviors;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class TriggerFinalizationWorkerBehavior(ILogger<TriggerFinalizationWorkerBehavior> Logger, IEnvelopeFinalizationTrigger? Trigger = null) : IPipelineBehavior<SigningCommand, Unit>
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="next"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
public async Task<Unit> Handle(SigningCommand request, RequestHandlerDelegate<Unit> next, CancellationToken cancellationToken)
|
|
{
|
|
if(Trigger != null)
|
|
try
|
|
{
|
|
|
|
await Trigger.TriggerAsync(cancellationToken);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
// Log the exception or handle it as needed
|
|
Logger.LogError(ex, "Error triggering finalization worker");
|
|
}
|
|
|
|
return await next(cancellationToken);
|
|
}
|
|
}
|