36 lines
1.0 KiB
C#
36 lines
1.0 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using Serilog;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using MassTransit;
|
|
using LCU.Library.Internal.ArchiverApiModel.Models;
|
|
using LCU.Api.Internal.ArchiverApi.Services;
|
|
using LCU.Library.Internal.Exceptions;
|
|
namespace LCU.Api.Internal.ArchiverApi.Consumers;
|
|
|
|
public class ArchiverConsumer : IConsumer<ArchiveRequest>
|
|
{
|
|
private readonly IServiceScopeFactory _scopeFactory;
|
|
|
|
public ArchiverConsumer(IServiceScopeFactory scopeFactory)
|
|
{
|
|
_scopeFactory = scopeFactory;
|
|
}
|
|
|
|
public async Task Consume(ConsumeContext<ArchiveRequest> context)
|
|
{
|
|
try
|
|
{
|
|
using var scope = _scopeFactory.CreateScope();
|
|
await Task.Run(() => scope.ServiceProvider.GetRequiredService<IArchiverService>().ExecuteRequest(context.Message));
|
|
}
|
|
catch (ServiceException)
|
|
{
|
|
return;
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Log.Fatal(exception, $"Unexpected Failure");
|
|
}
|
|
}
|
|
} |