Files
monorepo/LCU.API.Internal.MemberPreferencesApi/LCU.API.Internal.MemberPreferencesApi/Consumers/XdiBatchProcessConsumer.cs
T
2026-05-04 10:09:55 -05:00

30 lines
1.1 KiB
C#

using LCU.API.Internal.MemberPreferencesApi.Services.XdiServices;
using MassTransit;
namespace LCU.API.Internal.MemberPreferencesApi.Consumers;
public class XdiBatchProcessConsumer : IConsumer<XdiBatchProcessRequest>
{
private readonly IServiceScopeFactory _scopeFactory;
public XdiBatchProcessConsumer(IServiceScopeFactory scopeFactory)
{
_scopeFactory = scopeFactory;
}
public async Task Consume(ConsumeContext<XdiBatchProcessRequest> context)
{
try
{
using var scope = _scopeFactory.CreateScope();
await Task.Run(async () => await scope.ServiceProvider.GetRequiredService<IXdiBatchProcessService>().HandleXdiBatchProcess(context.Message));
}
catch (Exception exception)
{
Log.ForContext(Enum.GetName(typeof(PropertyEnum), PropertyEnum.Group),
Enum.GetName(typeof(GroupEnum), GroupEnum.ITDevelopment))
.Fatal(exception, $"Unexpected XdiBatchProcessConsumer Failure. " +
$"The response is placed on LCU.MemberPreferencesApi.XdiBatchProcess_error.");
throw;
}
}
}