fix: improve recovery and auto-start flows
This commit is contained in:
@@ -242,7 +242,7 @@ public sealed partial class FfmpegService : IFfmpegService
|
||||
|
||||
public async Task<bool> TryReconcileInactiveSessionAsync(Guid recordSessionId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (IsRunning(recordSessionId) || IsSessionUnderPostProcessing(recordSessionId))
|
||||
if (IsRunning(recordSessionId))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -269,11 +269,23 @@ public sealed partial class FfmpegService : IFfmpegService
|
||||
.ThenBy(static item => item.CreatedAt)
|
||||
.ToList();
|
||||
|
||||
var anyUsableOutput = false;
|
||||
var anyUsableOutput = tasks.Any(static item => item.Status == RecordTaskStatus.Completed);
|
||||
var hasBackgroundPostProcessing = false;
|
||||
string? sessionFinalizationError = null;
|
||||
|
||||
foreach (var task in tasks.Where(item => IsActiveTaskStatus(item.Status)))
|
||||
foreach (var task in tasks)
|
||||
{
|
||||
if (IsTaskUnderPostProcessing(task.Id))
|
||||
{
|
||||
hasBackgroundPostProcessing = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!IsActiveTaskStatus(task.Status))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var durationSeconds = task.StartedAt.HasValue
|
||||
? (double?)Math.Max(0, (endedAt - task.StartedAt.Value).TotalSeconds)
|
||||
: null;
|
||||
@@ -299,6 +311,7 @@ public sealed partial class FfmpegService : IFfmpegService
|
||||
if (IsLowStoragePauseError(taskFinalizationError))
|
||||
{
|
||||
task.MarkProcessing(taskFinalizationError, endedAt);
|
||||
hasBackgroundPostProcessing = true;
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(taskFinalizationError))
|
||||
{
|
||||
@@ -323,6 +336,12 @@ public sealed partial class FfmpegService : IFfmpegService
|
||||
{
|
||||
recordSession.MarkFailed(sessionFinalizationError, endedAt);
|
||||
}
|
||||
else if (hasBackgroundPostProcessing)
|
||||
{
|
||||
recordSession.MarkStopped(
|
||||
endedAt,
|
||||
"Recording process was no longer running when the session was reconciled. Post-processing will continue in background.");
|
||||
}
|
||||
else if (anyUsableOutput)
|
||||
{
|
||||
recordSession.MarkCompleted(endedAt);
|
||||
@@ -594,8 +613,8 @@ public sealed partial class FfmpegService : IFfmpegService
|
||||
private void ClearPostProcessState(Guid recordTaskId) =>
|
||||
_postProcessStates.TryRemove(recordTaskId, out _);
|
||||
|
||||
private bool IsSessionUnderPostProcessing(Guid recordSessionId) =>
|
||||
_postProcessStates.Values.Any(entry => entry.RecordSessionId == recordSessionId);
|
||||
private bool IsTaskUnderPostProcessing(Guid recordTaskId) =>
|
||||
_postProcessStates.ContainsKey(recordTaskId);
|
||||
|
||||
private async Task<IDisposable> AcquireTranscodeSlotAsync(int maxConcurrentTasks, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user