fix: restart live recording after session deletion
This commit is contained in:
@@ -276,6 +276,7 @@ public sealed class RecordService
|
||||
var deletedFilePaths = new List<string>();
|
||||
var deletedDanmakuPaths = new List<string>();
|
||||
var affectedSessionIds = new HashSet<Guid>();
|
||||
var affectedLiveRoomIds = new HashSet<Guid>();
|
||||
|
||||
foreach (var taskId in taskIds)
|
||||
{
|
||||
@@ -310,6 +311,7 @@ public sealed class RecordService
|
||||
_recordTaskRepository.Remove(recordTask);
|
||||
deletedTaskIds.Add(recordTask.Id);
|
||||
affectedSessionIds.Add(recordTask.RecordSessionId);
|
||||
affectedLiveRoomIds.Add(recordTask.LiveRoomId);
|
||||
}
|
||||
|
||||
var deletedSessionIds = new List<Guid>();
|
||||
@@ -357,6 +359,11 @@ public sealed class RecordService
|
||||
cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
if ((deletedTaskIds.Count > 0 || deletedSessionIds.Count > 0) && affectedLiveRoomIds.Count > 0)
|
||||
{
|
||||
await TryAutoRestartDeletedLiveRoomsAsync(affectedLiveRoomIds, cancellationToken);
|
||||
}
|
||||
|
||||
return new DeleteCompletedRecordTasksResultDto
|
||||
{
|
||||
DeletedTaskIds = deletedTaskIds,
|
||||
@@ -457,6 +464,80 @@ public sealed class RecordService
|
||||
}
|
||||
}
|
||||
|
||||
private async Task TryAutoRestartDeletedLiveRoomsAsync(
|
||||
IReadOnlyCollection<Guid> liveRoomIds,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (liveRoomIds.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var settings = await _systemSettingsService.GetAsync(cancellationToken);
|
||||
if (!settings.AutoStartRecordingOnLive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var storageCheck = _storageGuardService.CheckCanStartOrResume(settings);
|
||||
if (!storageCheck.HasEnoughSpace)
|
||||
{
|
||||
foreach (var liveRoomId in liveRoomIds)
|
||||
{
|
||||
await _systemLogService.WriteAsync(
|
||||
SystemLogLevel.Warning,
|
||||
"Storage",
|
||||
"Immediate auto-start after session deletion skipped because storage is below resume threshold.",
|
||||
storageCheck.Message,
|
||||
liveRoomId: liveRoomId,
|
||||
cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var liveRoomId in liveRoomIds)
|
||||
{
|
||||
var liveRoom = await _liveRoomRepository.GetByIdAsync(liveRoomId, cancellationToken);
|
||||
if (liveRoom is null || !liveRoom.IsEnabled || liveRoom.AvailabilityStatus != LiveRoomAvailabilityStatus.Live)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (await _recordSessionRepository.GetActiveByLiveRoomIdAsync(liveRoom.Id, cancellationToken) is not null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await _systemLogService.WriteAsync(
|
||||
SystemLogLevel.Info,
|
||||
"RecordSession",
|
||||
"Live room is still online after session deletion. Attempting immediate auto-start.",
|
||||
liveRoomId: liveRoom.Id,
|
||||
cancellationToken: cancellationToken);
|
||||
|
||||
await StartAsync(
|
||||
new StartRecordTaskRequest
|
||||
{
|
||||
LiveRoomId = liveRoom.Id
|
||||
},
|
||||
cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _systemLogService.WriteAsync(
|
||||
SystemLogLevel.Warning,
|
||||
"RecordSession",
|
||||
"Immediate auto-start after session deletion did not start a recording session.",
|
||||
ex.ToString(),
|
||||
liveRoomId: liveRoom.Id,
|
||||
cancellationToken: cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static DeleteCompletedRecordTasksResultDto CreateEmptyDeleteResult() => new()
|
||||
{
|
||||
DeletedTaskIds = [],
|
||||
|
||||
Reference in New Issue
Block a user