Browse Source

reduce hls segmenter disk use (#806)

pull/807/head
Jason Dove 4 years ago committed by GitHub
parent
commit
9fe03b6ef3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      CHANGELOG.md
  2. 12
      ErsatzTV.Application/Streaming/HlsSessionWorker.cs
  3. 14
      ErsatzTV/Services/RunOnce/CacheCleanerService.cs

2
CHANGELOG.md

@ -4,6 +4,8 @@ All notable changes to this project will be documented in this 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

12
ErsatzTV.Application/Streaming/HlsSessionWorker.cs

@ -21,6 +21,7 @@ public class HlsSessionWorker : IHlsSessionWorker @@ -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 @@ -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 @@ -153,6 +156,15 @@ public class HlsSessionWorker : IHlsSessionWorker
{
_timer.Elapsed -= Cancel;
}
try
{
_localFileSystem.EmptyFolder(Path.Combine(FileSystemLayout.TranscodeFolder, _channelNumber));
}
catch
{
// do nothing
}
}
}

14
ErsatzTV/Services/RunOnce/CacheCleanerService.cs

@ -23,8 +23,9 @@ public class CacheCleanerService : IHostedService @@ -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 @@ -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 @@ -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;

Loading…
Cancel
Save