using System; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Serilog; using MassTransit; using LCU.Api.Internal.FileOperations.Services; using LCU.Library.Internal.Exceptions; using LCU.Api.Internal.MaidBotLib.Models; using LCU.Library.Internal.FileOperationsModels.Models; namespace LCU.Api.Internal.FileOperations.Consumers; public class FileOperationsConsumer : IConsumer { private readonly IServiceScopeFactory _scopeFactory; public FileOperationsConsumer(IServiceScopeFactory scopeFactory) { _scopeFactory = scopeFactory; } public async Task Consume(ConsumeContext context) { try { using var scope = _scopeFactory.CreateScope(); await Task.Run(async () => await scope.ServiceProvider.GetRequiredService().HandleFileOperationsRequest(context.Message)); } catch (ServiceException) { //Masstransit handles the exception. https://masstransit-project.com/usage/exceptions.html#retry throw; } catch (Exception exception) { Log.ForContext(Enum.GetName(typeof(PropertyEnum), PropertyEnum.Group), Enum.GetName(typeof(GroupEnum), GroupEnum.ITDevelopment)) .Fatal(exception, $"Unexpected Failure in FileOperations Api"); //Masstransit handles the exception. https://masstransit-project.com/usage/exceptions.html#retry throw; } } }