Files
monorepo/LCU.API.Internal.FTP/LCU.Api.Internal.FTP/Consumers/SftpConsumer.cs
T
2026-03-24 15:28:37 -05:00

42 lines
1.4 KiB
C#

using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Serilog;
using MassTransit;
using LCU.Api.Internal.FTP.Services;
using LCU.Api.Internal.FTPLib.Models;
using LCU.Library.Internal.Exceptions;
using LCU.Api.Internal.MaidBotLib.Models;
namespace LCU.Api.Internal.FTP.Consumers;
public class SftpConsumer : IConsumer<QueueRequest>
{
private readonly IServiceScopeFactory _scopeFactory;
public SftpConsumer(IServiceScopeFactory scopeFactory)
{
_scopeFactory = scopeFactory;
}
public async Task Consume(ConsumeContext<QueueRequest> context)
{
try
{
using var scope = _scopeFactory.CreateScope();
await Task.Run(() => scope.ServiceProvider.GetRequiredService<IFtpService>().HandleFtpRequest(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");
//Masstransit handles the exception. https://masstransit-project.com/usage/exceptions.html#retry
throw;
}
}
}