fix: remove short fragment recovery scan
This commit is contained in:
@@ -98,8 +98,6 @@ public sealed class LiveRoomPollingBackgroundService : BackgroundService, ILiveR
|
||||
// insufficient to remux, and it is retried every poll cycle.
|
||||
await ffmpegService.ResumePausedFinalizationsAsync(stoppingToken);
|
||||
await ffmpegService.ResumeArtifactRepairsAsync(stoppingToken);
|
||||
var shortFragmentRecovery = scope.ServiceProvider.GetRequiredService<ShortFragmentConsolidationService>();
|
||||
await shortFragmentRecovery.ResumeInterruptedMergesAsync(stoppingToken);
|
||||
|
||||
if (!settings.EnableBackgroundPolling)
|
||||
{
|
||||
|
||||
@@ -108,56 +108,6 @@ public sealed class ShortFragmentConsolidationService
|
||||
: FragmentDispatchDecision.Wait("短分片合并失败,原文件已保留,将自动重试。", TimeSpan.FromMinutes(1));
|
||||
}
|
||||
|
||||
public async Task<int> ResumeInterruptedMergesAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var sources = await _dbContext.RecordTasks
|
||||
.AsNoTracking()
|
||||
.Include(item => item.Result)
|
||||
.Where(item => item.IsHiddenArtifactSource && item.Result != null)
|
||||
.OrderByDescending(item => item.UpdatedAt)
|
||||
.Take(100)
|
||||
.ToListAsync(cancellationToken);
|
||||
var manifests = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var source in sources)
|
||||
{
|
||||
var parent = Path.GetDirectoryName(Path.GetFullPath(source.Result!.FilePath));
|
||||
var recoveryBase = parent is null ? null : Path.Combine(parent, ".liverecorder-recovery", source.RecordSessionId.ToString("N"));
|
||||
if (recoveryBase is null || !Directory.Exists(recoveryBase)) continue;
|
||||
foreach (var path in Directory.EnumerateFiles(recoveryBase, "manifest.json", SearchOption.AllDirectories).Take(100)) manifests.Add(path);
|
||||
}
|
||||
|
||||
var resumed = 0;
|
||||
foreach (var path in manifests)
|
||||
{
|
||||
try
|
||||
{
|
||||
var manifest = JsonSerializer.Deserialize<MergeRecoveryManifest>(await File.ReadAllTextAsync(path, cancellationToken));
|
||||
if (manifest is null || manifest.Phase == "completed" || string.IsNullOrWhiteSpace(manifest.MergedPath)) continue;
|
||||
var targetPath = await _dbContext.RecordTasks
|
||||
.AsNoTracking()
|
||||
.Where(item => item.Id == manifest.TargetRecordTaskId && item.Result != null)
|
||||
.Select(item => item.Result!.FilePath)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
if (!File.Exists(manifest.MergedPath) || !string.Equals(Path.GetFullPath(targetPath ?? string.Empty), Path.GetFullPath(manifest.MergedPath), StringComparison.OrdinalIgnoreCase)) continue;
|
||||
|
||||
foreach (var source in manifest.Sources)
|
||||
{
|
||||
CopyToRecovery(source.VideoPath, manifest.RecoveryDirectory);
|
||||
CopyToRecovery(source.DanmakuPath, manifest.RecoveryDirectory);
|
||||
DeleteOriginal(source.VideoPath, manifest.MergedPath);
|
||||
DeleteOriginal(source.DanmakuPath, Path.ChangeExtension(manifest.MergedPath, ".xml"));
|
||||
}
|
||||
await WriteManifestAsync(manifest.RecoveryDirectory, manifest with { Phase = "completed" }, cancellationToken);
|
||||
resumed++;
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or JsonException)
|
||||
{
|
||||
_logger.LogWarning(ex, "Unable to resume short-fragment recovery manifest {ManifestPath}", path);
|
||||
}
|
||||
}
|
||||
return resumed;
|
||||
}
|
||||
|
||||
private static List<RecordTask> ResolveMergeGroup(IReadOnlyList<RecordTask> tasks, int index)
|
||||
{
|
||||
var durations = tasks
|
||||
|
||||
Reference in New Issue
Block a user