2024-02-02 17:14:41 +08:00
|
|
|
|
using MesETL.App.HostedServices.Abstractions;
|
|
|
|
|
using MesETL.App.Services;
|
2023-12-29 16:16:05 +08:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
2024-02-02 17:14:41 +08:00
|
|
|
|
namespace MesETL.App.HostedServices;
|
2023-12-29 16:16:05 +08:00
|
|
|
|
|
2024-01-04 09:00:44 +08:00
|
|
|
|
// 空输出服务,测试用
|
|
|
|
|
public class VoidOutputService : IOutputService
|
2023-12-29 16:16:05 +08:00
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
2024-01-29 09:29:16 +08:00
|
|
|
|
private readonly RecordQueuePool _queuePool;
|
2023-12-29 16:16:05 +08:00
|
|
|
|
private readonly ProcessContext _context;
|
|
|
|
|
|
2024-01-29 09:29:16 +08:00
|
|
|
|
public VoidOutputService(
|
|
|
|
|
ProcessContext context, ILogger<VoidOutputService> logger, RecordQueuePool queuePool)
|
2023-12-29 16:16:05 +08:00
|
|
|
|
{
|
|
|
|
|
_context = context;
|
|
|
|
|
_logger = logger;
|
2024-01-29 09:29:16 +08:00
|
|
|
|
_queuePool = queuePool;
|
2023-12-29 16:16:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-29 09:29:16 +08:00
|
|
|
|
public Task ExecuteAsync(CancellationToken ct)
|
2023-12-29 16:16:05 +08:00
|
|
|
|
{
|
2024-01-29 09:29:16 +08:00
|
|
|
|
_logger.LogInformation("***** Void Output Service Started *****");
|
|
|
|
|
while (!_context.IsTransformCompleted || _queuePool.Queues.Count > 0)
|
2023-12-29 16:16:05 +08:00
|
|
|
|
{
|
2024-02-10 17:12:26 +08:00
|
|
|
|
foreach (var pair in _queuePool.Queues)
|
2024-01-29 09:29:16 +08:00
|
|
|
|
{
|
|
|
|
|
if (_context.IsTransformCompleted && pair.Value.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
_queuePool.RemoveQueue(pair.Key);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if(!pair.Value.TryDequeue(out var record)) continue;
|
2023-12-29 16:16:05 +08:00
|
|
|
|
_context.AddOutput();
|
2024-01-29 09:29:16 +08:00
|
|
|
|
}
|
2023-12-29 16:16:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_context.CompleteOutput();
|
2024-01-29 09:29:16 +08:00
|
|
|
|
_logger.LogInformation("***** Void Output Service Stopped *****");
|
2023-12-29 16:16:05 +08:00
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
}
|