using System.Numerics; using MesETL.App.HostedServices.Abstractions; using MesETL.App.Services; using Microsoft.Extensions.Logging; namespace MesETL.App.HostedServices; // 空输出服务,测试用 public class VoidOutputService : IOutputService { private readonly ILogger _logger; private readonly RecordQueuePool _queuePool; private readonly ProcessContext _context; private BigInteger _total; public VoidOutputService( ProcessContext context, ILogger logger, RecordQueuePool queuePool) { _context = context; _logger = logger; _queuePool = queuePool; } public Task ExecuteAsync(CancellationToken ct) { _logger.LogInformation("***** Void Output Service Started *****"); while (!_context.IsTransformCompleted || _queuePool.Queues.Count > 0) { foreach (var pair in _queuePool.Queues) { if (_context.IsTransformCompleted && pair.Value.Count == 0) { _queuePool.RemoveQueue(pair.Key); continue; } if (!pair.Value.TryDequeue(out var record)) continue; _total += record.FieldCharCount; _context.AddOutput(); } } _context.CompleteOutput(); _logger.LogInformation("***** Void Output Service Stopped *****"); _logger.LogInformation("平均列字符数:{Number}", _total / _context.OutputCount); return Task.CompletedTask; } }