fix: restore scheduler auto-start on sqlite
This commit is contained in:
@@ -412,10 +412,13 @@ public sealed partial class FfmpegService : IFfmpegService
|
||||
.Include(item => item.Result)
|
||||
.Where(item => item.OutputFormat == RecordOutputFormat.Mp4 &&
|
||||
(item.Status == RecordTaskStatus.Processing ||
|
||||
item.Status == RecordTaskStatus.Completed))
|
||||
item.Status == RecordTaskStatus.Completed))
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
candidates = candidates
|
||||
.OrderBy(static item => item.UpdatedAt)
|
||||
.Take(100)
|
||||
.ToListAsync(cancellationToken);
|
||||
.ToList();
|
||||
|
||||
var queuedTaskIds = new List<Guid>();
|
||||
var repairedInterruptedTasks = 0;
|
||||
|
||||
@@ -184,6 +184,22 @@ public sealed class LiveRoomPollingBackgroundService : BackgroundService
|
||||
return;
|
||||
}
|
||||
|
||||
var reconciledStaleSessionIds = await ReconcileStaleActiveSessionsAsync(
|
||||
dbContext,
|
||||
ffmpegService,
|
||||
liveRoom.Id,
|
||||
cancellationToken);
|
||||
foreach (var reconciledSessionId in reconciledStaleSessionIds)
|
||||
{
|
||||
await logService.WriteAsync(
|
||||
SystemLogLevel.Warning,
|
||||
"Scheduler",
|
||||
"Recovered a stale active recording session before auto-start check.",
|
||||
liveRoomId: liveRoom.Id,
|
||||
recordSessionId: reconciledSessionId,
|
||||
cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
var hasRunningSession = await dbContext.RecordSessions.AnyAsync(
|
||||
item => item.LiveRoomId == liveRoom.Id &&
|
||||
(item.Status == RecordSessionStatus.Starting ||
|
||||
@@ -368,6 +384,41 @@ public sealed class LiveRoomPollingBackgroundService : BackgroundService
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<IReadOnlyList<Guid>> ReconcileStaleActiveSessionsAsync(
|
||||
LiveRecorderDbContext dbContext,
|
||||
IFfmpegService ffmpegService,
|
||||
Guid liveRoomId,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var activeSessionIds = await dbContext.RecordSessions
|
||||
.Where(item => item.LiveRoomId == liveRoomId &&
|
||||
(item.Status == RecordSessionStatus.Starting ||
|
||||
item.Status == RecordSessionStatus.Running ||
|
||||
item.Status == RecordSessionStatus.Stopping))
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
var orderedActiveSessionIds = activeSessionIds
|
||||
.OrderBy(item => item.CreatedAt)
|
||||
.Select(item => item.Id)
|
||||
.ToList();
|
||||
|
||||
if (orderedActiveSessionIds.Count == 0)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
var reconciledSessionIds = new List<Guid>();
|
||||
foreach (var activeSessionId in orderedActiveSessionIds)
|
||||
{
|
||||
if (await ffmpegService.TryReconcileInactiveSessionAsync(activeSessionId, cancellationToken))
|
||||
{
|
||||
reconciledSessionIds.Add(activeSessionId);
|
||||
}
|
||||
}
|
||||
|
||||
return reconciledSessionIds;
|
||||
}
|
||||
|
||||
private static bool IsTransientPollingException(Exception exception, CancellationToken cancellationToken)
|
||||
{
|
||||
if (exception is OperationCanceledException && cancellationToken.IsCancellationRequested)
|
||||
|
||||
Reference in New Issue
Block a user