mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-21 17:51:13 +00:00
8b0ddae075
Phase B of architecture coupling refactor (epic AZ-309). Replaces the monolithic SatelliteProvider.Services with three per-component csprojs to add a compiler-enforced module boundary (resolves F4): - SatelliteProvider.Services.TileDownloader - SatelliteProvider.Services.RegionProcessing - SatelliteProvider.Services.RouteManagement DI registrations relocated into per-component AddTileDownloader / AddRegionProcessing / AddRouteManagement extension methods called from Program.cs. RateLimitException moved to Common/Exceptions/ to keep the three new csprojs as siblings (no Region->TileDownloader ProjectReference). Dockerfiles and consumer csprojs (Api, Tests) rewired to the new project paths. No DI lifetime or hosted-service order changes. Build: 0 warn, 0 err. Unit tests: 40/40. Smoke integration: green. Co-authored-by: Cursor <cursoragent@cursor.com>
48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
using System.Threading.Channels;
|
|
using Microsoft.Extensions.Logging;
|
|
using SatelliteProvider.Common.DTO;
|
|
using SatelliteProvider.Common.Interfaces;
|
|
|
|
namespace SatelliteProvider.Services.RegionProcessing;
|
|
|
|
public class RegionRequestQueue : IRegionRequestQueue
|
|
{
|
|
private readonly Channel<RegionRequest> _queue;
|
|
private readonly ILogger<RegionRequestQueue>? _logger;
|
|
private int _totalEnqueued = 0;
|
|
private int _totalDequeued = 0;
|
|
|
|
public RegionRequestQueue(int capacity, ILogger<RegionRequestQueue>? logger = null)
|
|
{
|
|
var options = new BoundedChannelOptions(capacity)
|
|
{
|
|
FullMode = BoundedChannelFullMode.Wait
|
|
};
|
|
_queue = Channel.CreateBounded<RegionRequest>(options);
|
|
_logger = logger;
|
|
_logger?.LogInformation("RegionRequestQueue created with capacity {Capacity}", capacity);
|
|
}
|
|
|
|
public async ValueTask EnqueueAsync(RegionRequest request, CancellationToken cancellationToken = default)
|
|
{
|
|
_totalEnqueued++;
|
|
await _queue.Writer.WriteAsync(request, cancellationToken);
|
|
}
|
|
|
|
public async ValueTask<RegionRequest?> DequeueAsync(CancellationToken cancellationToken = default)
|
|
{
|
|
if (await _queue.Reader.WaitToReadAsync(cancellationToken))
|
|
{
|
|
if (_queue.Reader.TryRead(out var request))
|
|
{
|
|
_totalDequeued++;
|
|
return request;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public int Count => _queue.Reader.Count;
|
|
}
|
|
|