using PlotLine.Data; namespace PlotLine.Services; // Central reservation recovery only; AI execution continues through existing feature workers/services. public sealed class AiAllowanceMaintenance(IServiceScopeFactory scopes,ILogger logger):BackgroundService { protected override async Task ExecuteAsync(CancellationToken stoppingToken) { using var timer=new PeriodicTimer(TimeSpan.FromMinutes(5)); do{try{using var scope=scopes.CreateScope();var events=await scope.ServiceProvider.GetRequiredService().Expire();var notifier=scope.ServiceProvider.GetRequiredService();foreach(var progress in events)await notifier.PublishCharacterEnrichmentAsync(progress);}catch(Exception error)when(error is not OperationCanceledException){logger.LogWarning(error,"AI reservation expiry maintenance failed; reservations remain durably recorded.");}}while(await timer.WaitForNextTickAsync(stoppingToken)); } }