Files
monorepo/LCU.API.Internal.MemberPreferencesApi/LCU.API.Internal.MemberPreferencesApi/Consumers/AgreementDnaFieldChangeConsumer.cs
T
2026-03-31 16:43:12 -05:00

43 lines
1.9 KiB
C#

using LCU.API.Internal.MemberPreferencesApi.Services.DnaAuditServices;
using MassTransit;
namespace LCU.API.Internal.MemberPreferencesApi.Consumers;
public class AgreementDnaFieldChangeConsumer : IConsumer<DnaFieldChangeRequest>
{
private readonly IServiceScopeFactory _scopeFactory;
public AgreementDnaFieldChangeConsumer(IServiceScopeFactory scopeFactory)
{
_scopeFactory = scopeFactory;
}
public async Task Consume(ConsumeContext<DnaFieldChangeRequest> context)
{
try
{
Log.Debug("Starting AgreementDnaFieldChangeConsumer.");
Log.Information($"New Agreement Received for : {context.Message.DnaProcessType} Process - {context.Message.DnaFieldIdInformation}");
using var scope = _scopeFactory.CreateScope();
await Task.Run(async () => await scope.ServiceProvider.GetRequiredService<IDNADataAuditService>().HandleAgreementAuditCheck(context.Message));
Log.Debug("Ending AgreementDnaFieldChangeConsumer.");
}
catch (ServiceException serviceException)
{
Log.ForContext(Enum.GetName(typeof(PropertyEnum), PropertyEnum.Group),
Enum.GetName(typeof(GroupEnum), GroupEnum.ITDevelopment))
.Error(serviceException, $"AgreementDnaFieldChangeConsumer Failure. " +
$"The request is placed on AgreementDnaFieldChangeConsumer_error.");
throw;
}
catch (Exception exception)
{
Log.ForContext(Enum.GetName(typeof(PropertyEnum), PropertyEnum.Group),
Enum.GetName(typeof(GroupEnum), GroupEnum.ITDevelopment))
.Fatal(exception, $"Unexpected AgreementDnaFieldChangeConsumer Failure. " +
$"The TransactionRequest is placed on AgreementDnaFieldChangeConsumer_error.");
throw;
}
}
}