namespace QuestionsApi.Services; public sealed class CreditLedgerReconciliationService( CreditStore credits, ILogger logger) : BackgroundService { protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { try { await credits.ReconcilePendingAsync(stoppingToken); } catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested) { return; } catch (Exception exception) { logger.LogError(exception, "Credit ledger reconciliation failed."); } await Task.Delay(TimeSpan.FromMinutes(1), stoppingToken); } } }