using System; using System.Threading.Tasks; using Serilog; using Microsoft.Extensions.DependencyInjection; using MassTransit; using LCU.Api.Internal.ArchiverApi.Services; using ApiResponse = LCU.Library.Internal.ApiResponse.Models; using LCU.Library.Internal.Exceptions; namespace LCU.Api.Internal.ArchiverApi.Consumers; public class ResponseConsumer : IConsumer { private readonly IServiceScopeFactory _scopeFactory; public ResponseConsumer(IServiceScopeFactory scopeFactory) { _scopeFactory = scopeFactory; } public async Task Consume(ConsumeContext context) { try { using var scope = _scopeFactory.CreateScope(); await Task.Run(() => scope.ServiceProvider.GetRequiredService().HandleReportArchiveCompletedRequest(context.Message)); } catch (ServiceException) { return; } catch (Exception exception) { Log.Fatal(exception, $"Unexpected Failure"); } } }