From e640d5b5cc931a3db24fdcf9ed5ddf0df2512331 Mon Sep 17 00:00:00 2001 From: nanxun Date: Fri, 5 Jun 2026 11:57:20 +0800 Subject: [PATCH] fix: consolidate storage tier with old MB thresholds into single tier system - CanStartNewRecording now purely based on Tier==Green (was HasEnoughSpace||Green) - PollingBackgroundService now uses ShouldPauseActive instead of MB-based CheckShouldPause - Both pause and start checks consolidated into single guardCheck call - Old MB pause/resume thresholds still work as secondary safety via hasEnoughSpace Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com --- .../Storage/IStorageGuardService.cs | 6 ++- .../LiveRoomPollingBackgroundService.cs | 44 +++++++++---------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/LiveRecorder.Application/Abstractions/Storage/IStorageGuardService.cs b/src/LiveRecorder.Application/Abstractions/Storage/IStorageGuardService.cs index c304f92..d782ee4 100644 --- a/src/LiveRecorder.Application/Abstractions/Storage/IStorageGuardService.cs +++ b/src/LiveRecorder.Application/Abstractions/Storage/IStorageGuardService.cs @@ -40,12 +40,14 @@ public sealed record StorageGuardResult( public double UsagePercent { get; init; } /// - /// True if new recordings can be started. False in Yellow and Red tiers. + /// True if new recordings can be started. Only true in Green tier. + /// This replaces the old binary HasEnoughSpace check — the tier system is the single source of truth. /// - public bool CanStartNewRecording => HasEnoughSpace || Tier == StorageTier.Green; + public bool CanStartNewRecording => Tier == StorageTier.Green; /// /// True if active recordings should be paused. Only true in Red tier. + /// This replaces the old MB-based CheckShouldPause — consolidated into the tier system. /// public bool ShouldPauseActive => Tier == StorageTier.Red; } diff --git a/src/LiveRecorder.Infrastructure/Services/LiveRoomPollingBackgroundService.cs b/src/LiveRecorder.Infrastructure/Services/LiveRoomPollingBackgroundService.cs index a8f3f51..d58338f 100644 --- a/src/LiveRecorder.Infrastructure/Services/LiveRoomPollingBackgroundService.cs +++ b/src/LiveRecorder.Infrastructure/Services/LiveRoomPollingBackgroundService.cs @@ -355,8 +355,8 @@ public sealed class LiveRoomPollingBackgroundService : BackgroundService, ILiveR return; } - var pauseCheck = storageGuardService.CheckShouldPause(settings); - if (!pauseCheck.HasEnoughSpace) + var guardCheck = storageGuardService.CheckCanStartOrResume(settings); + if (guardCheck.ShouldPauseActive) { await PauseActiveSessionsForLowStorageAsync( dbContext, @@ -366,7 +366,7 @@ public sealed class LiveRoomPollingBackgroundService : BackgroundService, ILiveR webhookNotificationService, liveRoom, liveRoom.Id, - pauseCheck.Message, + guardCheck.Message, cancellationToken); } @@ -382,25 +382,6 @@ public sealed class LiveRoomPollingBackgroundService : BackgroundService, ILiveR return; } - var startCheck = storageGuardService.CheckCanStartOrResume(settings); - if (!startCheck.CanStartNewRecording) - { - await UpdateAutoStartDecisionAsync( - dbContext, - liveRoom, - AutoStartDecisionCodes.SkippedStorage, - $"Auto-start skipped because storage tier is {startCheck.Tier}.", - startCheck.Message, - cancellationToken); - await logService.WriteAsync( - SystemLogLevel.Warning, - "Storage", - "Auto-start recording skipped because storage is below resume threshold.", - startCheck.Message, - liveRoomId: liveRoom.Id, - cancellationToken: cancellationToken); - return; - } var reconciledStaleSessionIds = await ReconcileStaleActiveSessionsAsync( dbContext, @@ -418,6 +399,25 @@ public sealed class LiveRoomPollingBackgroundService : BackgroundService, ILiveR cancellationToken: cancellationToken); } + if (!guardCheck.CanStartNewRecording) + { + await UpdateAutoStartDecisionAsync( + dbContext, + liveRoom, + AutoStartDecisionCodes.SkippedStorage, + $"Auto-start skipped because storage tier is {guardCheck.Tier}.", + guardCheck.Message, + cancellationToken); + await logService.WriteAsync( + SystemLogLevel.Warning, + "Storage", + "Auto-start recording skipped because storage tier is not Green.", + guardCheck.Message, + liveRoomId: liveRoom.Id, + cancellationToken: cancellationToken); + return; + } + var hasRunningSession = await dbContext.RecordSessions.AnyAsync( item => item.LiveRoomId == liveRoom.Id && (item.Status == RecordSessionStatus.Starting ||