fix: reconcile sessions before auto-start

This commit is contained in:
2026-04-25 22:36:10 +08:00
parent aa548db980
commit ff3e1fae70
2 changed files with 14 additions and 0 deletions
@@ -126,9 +126,17 @@ public sealed class RecordService
throw new InvalidOperationException("The live room is disabled. Enable it before starting a recording."); throw new InvalidOperationException("The live room is disabled. Enable it before starting a recording.");
} }
await ReconcileActiveSessionsAsync(liveRoom.Id, cancellationToken);
var activeSession = await _recordSessionRepository.GetActiveByLiveRoomIdAsync(liveRoom.Id, cancellationToken); var activeSession = await _recordSessionRepository.GetActiveByLiveRoomIdAsync(liveRoom.Id, cancellationToken);
if (activeSession is not null) if (activeSession is not null)
{ {
await _systemLogService.WriteAsync(
SystemLogLevel.Warning,
"RecordSession",
"Recording start skipped because an active session still exists after reconciliation.",
liveRoomId: liveRoom.Id,
recordSessionId: activeSession.Id,
cancellationToken: cancellationToken);
throw new InvalidOperationException("An active recording session already exists for the live room."); throw new InvalidOperationException("An active recording session already exists for the live room.");
} }
@@ -216,6 +216,12 @@ public sealed class LiveRoomPollingBackgroundService : BackgroundService
if (hasRunningSession) if (hasRunningSession)
{ {
await logService.WriteAsync(
SystemLogLevel.Info,
"Scheduler",
"Auto-start skipped because an active recording session already exists.",
liveRoomId: liveRoom.Id,
cancellationToken: cancellationToken);
return; return;
} }