47 lines
1.8 KiB
C#
47 lines
1.8 KiB
C#
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using LCU.API.Collections.RepoApi.Configuration;
|
|
using LCU.API.Collections.RepoApi.Services;
|
|
using LCU.Shared.Realtime.QueueLib.Models;
|
|
using LCU.Shared.Realtime.QueueLib.Queue;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Serilog;
|
|
|
|
namespace LCU.API.Collections.RepoApi.HostedServices
|
|
{
|
|
public class HostedAutoImsTaskConsumer : BackgroundService, IQueueItemProcessor
|
|
{
|
|
private readonly IServiceScopeFactory _scopeFactory;
|
|
private readonly IQueueConnectionConfig _configuration;
|
|
private readonly IQueueConsumerConfig _consumerConfig;
|
|
|
|
public HostedAutoImsTaskConsumer(IQueueConnectionConfig configuration, RepoApiConfiguration repoApiConfiguration, IServiceScopeFactory scopeFactory)
|
|
{
|
|
_configuration = configuration;
|
|
_scopeFactory = scopeFactory;
|
|
_consumerConfig = repoApiConfiguration.QueueConsumerConfigs["AutoImsTask"];
|
|
}
|
|
|
|
protected override async Task ExecuteAsync(CancellationToken cancellationToken)
|
|
{
|
|
Log.Information("[QueueLib] Hosted Queue Producer is starting.");
|
|
|
|
var proxyQueue = new QueueItemConsumer(_configuration, _consumerConfig, this);
|
|
|
|
await proxyQueue.ProcessItems(cancellationToken, true, 0);
|
|
|
|
Log.Information("[QueueLib] Hosted Queue Producer is stopping.");
|
|
}
|
|
|
|
public void HandleItem(QueueItem item)
|
|
{
|
|
using (var scope = _scopeFactory.CreateScope())
|
|
{
|
|
var processor = scope.ServiceProvider.GetService<AutoImsService>();
|
|
var files = processor.Download();
|
|
processor.ProcessDownloadedFiles(files);
|
|
}
|
|
}
|
|
}
|
|
} |