reduce hls segmenter disk use (#806)

This commit is contained in:
Jason Dove
2022-05-16 21:45:13 -05:00
committed by GitHub
parent f895ab5304
commit 9fe03b6ef3
3 changed files with 24 additions and 4 deletions
+2
View File
@@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [Unreleased]
### Added
- Clean transcode cache folder on startup and after `HLS Segmenter` session terminates for any reason
## [0.5.7-beta] - 2022-05-14
### Fixed
@@ -21,6 +21,7 @@ public class HlsSessionWorker : IHlsSessionWorker
private static readonly SemaphoreSlim Slim = new(1, 1);
private static int _workAheadCount;
private readonly IHlsPlaylistFilter _hlsPlaylistFilter;
private readonly ILocalFileSystem _localFileSystem;
private readonly ILogger<HlsSessionWorker> _logger;
private readonly IServiceScopeFactory _serviceScopeFactory;
private readonly object _sync = new();
@@ -34,10 +35,12 @@ public class HlsSessionWorker : IHlsSessionWorker
public HlsSessionWorker(
IHlsPlaylistFilter hlsPlaylistFilter,
IServiceScopeFactory serviceScopeFactory,
ILocalFileSystem localFileSystem,
ILogger<HlsSessionWorker> logger)
{
_hlsPlaylistFilter = hlsPlaylistFilter;
_serviceScopeFactory = serviceScopeFactory;
_localFileSystem = localFileSystem;
_logger = logger;
}
@@ -153,6 +156,15 @@ public class HlsSessionWorker : IHlsSessionWorker
{
_timer.Elapsed -= Cancel;
}
try
{
_localFileSystem.EmptyFolder(Path.Combine(FileSystemLayout.TranscodeFolder, _channelNumber));
}
catch
{
// do nothing
}
}
}
@@ -23,8 +23,9 @@ public class CacheCleanerService : IHostedService
{
using IServiceScope scope = _serviceScopeFactory.CreateScope();
await using TvContext dbContext = scope.ServiceProvider.GetRequiredService<TvContext>();
ILocalFileSystem localFileSystem = scope.ServiceProvider.GetRequiredService<ILocalFileSystem>();
if (Directory.Exists(FileSystemLayout.LegacyImageCacheFolder))
if (localFileSystem.FolderExists(FileSystemLayout.LegacyImageCacheFolder))
{
_logger.LogInformation("Migrating channel logos from legacy image cache folder");
@@ -34,13 +35,12 @@ public class CacheCleanerService : IHostedService
.Map(a => a.Path)
.ToListAsync(cancellationToken);
ILocalFileSystem localFileSystem = scope.ServiceProvider.GetRequiredService<ILocalFileSystem>();
foreach (string logo in logos)
{
string legacyPath = Path.Combine(FileSystemLayout.LegacyImageCacheFolder, logo);
if (File.Exists(legacyPath))
if (localFileSystem.FileExists(legacyPath))
{
string subfolder = logo.Substring(0, 2);
string subfolder = logo[..2];
string newPath = Path.Combine(FileSystemLayout.LogoCacheFolder, subfolder, logo);
await localFileSystem.CopyFile(legacyPath, newPath);
}
@@ -49,6 +49,12 @@ public class CacheCleanerService : IHostedService
_logger.LogInformation("Deleting legacy image cache folder");
Directory.Delete(FileSystemLayout.LegacyImageCacheFolder, true);
}
if (localFileSystem.FolderExists(FileSystemLayout.TranscodeFolder))
{
_logger.LogInformation("Emptying transcode cache folder");
localFileSystem.EmptyFolder(FileSystemLayout.TranscodeFolder);
}
}
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;