recalculate all files on cleanup task (wtf metrics discrepancies)
This commit is contained in:
@@ -30,15 +30,8 @@ public class FileCleanupService : IHostedService
|
|||||||
{
|
{
|
||||||
_logger.LogInformation("Cleanup Service started");
|
_logger.LogInformation("Cleanup Service started");
|
||||||
|
|
||||||
_logger.LogInformation("Calculating initial files");
|
|
||||||
|
|
||||||
_cleanupCts = new();
|
_cleanupCts = new();
|
||||||
|
|
||||||
DirectoryInfo dir = new(_cacheDir);
|
|
||||||
var allFiles = dir.GetFiles("*", SearchOption.AllDirectories);
|
|
||||||
_metrics.SetGaugeTo(MetricsAPI.GaugeFilesTotalSize, allFiles.Sum(f => f.Length));
|
|
||||||
_metrics.SetGaugeTo(MetricsAPI.GaugeFilesTotal, allFiles.Length);
|
|
||||||
|
|
||||||
_ = CleanUpTask(_cleanupCts.Token);
|
_ = CleanUpTask(_cleanupCts.Token);
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
@@ -50,6 +43,11 @@ public class FileCleanupService : IHostedService
|
|||||||
|
|
||||||
while (!ct.IsCancellationRequested)
|
while (!ct.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
|
DirectoryInfo dir = new(_cacheDir);
|
||||||
|
var allFiles = dir.GetFiles("*", SearchOption.AllDirectories);
|
||||||
|
_metrics.SetGaugeTo(MetricsAPI.GaugeFilesTotalSize, allFiles.Sum(f => f.Length));
|
||||||
|
_metrics.SetGaugeTo(MetricsAPI.GaugeFilesTotal, allFiles.Length);
|
||||||
|
|
||||||
using var scope = _services.CreateScope();
|
using var scope = _services.CreateScope();
|
||||||
using var dbContext = scope.ServiceProvider.GetService<MareDbContext>()!;
|
using var dbContext = scope.ServiceProvider.GetService<MareDbContext>()!;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user