36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
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<ApiResponse.Response>
|
|
{
|
|
private readonly IServiceScopeFactory _scopeFactory;
|
|
|
|
public ResponseConsumer(IServiceScopeFactory scopeFactory)
|
|
{
|
|
_scopeFactory = scopeFactory;
|
|
}
|
|
|
|
public async Task Consume(ConsumeContext<ApiResponse.Response> context)
|
|
{
|
|
try
|
|
{
|
|
using var scope = _scopeFactory.CreateScope();
|
|
await Task.Run(() => scope.ServiceProvider.GetRequiredService<IArchiveCompletionService>().HandleReportArchiveCompletedRequest(context.Message));
|
|
}
|
|
catch (ServiceException)
|
|
{
|
|
return;
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Log.Fatal(exception, $"Unexpected Failure");
|
|
}
|
|
}
|
|
} |