make cleanup check time configurable, add distribution file server address
This commit is contained in:
@@ -7,6 +7,7 @@ public class StaticFilesServerConfiguration : MareConfigurationBase
|
|||||||
{
|
{
|
||||||
public bool IsDistributionNode { get; set; } = false;
|
public bool IsDistributionNode { get; set; } = false;
|
||||||
public Uri? MainFileServerAddress { get; set; } = null;
|
public Uri? MainFileServerAddress { get; set; } = null;
|
||||||
|
public Uri? DistributionFileServerAddress { get; set; } = null;
|
||||||
public int ForcedDeletionOfFilesAfterHours { get; set; } = -1;
|
public int ForcedDeletionOfFilesAfterHours { get; set; } = -1;
|
||||||
public double CacheSizeHardLimitInGiB { get; set; } = -1;
|
public double CacheSizeHardLimitInGiB { get; set; } = -1;
|
||||||
public int UnusedFileRetentionPeriodInDays { get; set; } = 14;
|
public int UnusedFileRetentionPeriodInDays { get; set; } = 14;
|
||||||
@@ -15,6 +16,7 @@ public class StaticFilesServerConfiguration : MareConfigurationBase
|
|||||||
public int DownloadTimeoutSeconds { get; set; } = 5;
|
public int DownloadTimeoutSeconds { get; set; } = 5;
|
||||||
public int DownloadQueueReleaseSeconds { get; set; } = 15;
|
public int DownloadQueueReleaseSeconds { get; set; } = 15;
|
||||||
public int DownloadQueueClearLimit { get; set; } = 15000;
|
public int DownloadQueueClearLimit { get; set; } = 15000;
|
||||||
|
public int CleanupCheckInMinutes { get; set; } = 15;
|
||||||
[RemoteConfiguration]
|
[RemoteConfiguration]
|
||||||
public Uri CdnFullUrl { get; set; } = null;
|
public Uri CdnFullUrl { get; set; } = null;
|
||||||
[RemoteConfiguration]
|
[RemoteConfiguration]
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public sealed class CachedFileProvider : IDisposable
|
|||||||
_fileStatisticsService = fileStatisticsService;
|
_fileStatisticsService = fileStatisticsService;
|
||||||
_metrics = metrics;
|
_metrics = metrics;
|
||||||
_generator = generator;
|
_generator = generator;
|
||||||
_remoteCacheSourceUri = configuration.GetValueOrDefault<Uri>(nameof(StaticFilesServerConfiguration.MainFileServerAddress), null);
|
_remoteCacheSourceUri = configuration.GetValueOrDefault<Uri>(nameof(StaticFilesServerConfiguration.DistributionFileServerAddress), null);
|
||||||
_isDistributionServer = configuration.GetValueOrDefault(nameof(StaticFilesServerConfiguration.IsDistributionNode), false);
|
_isDistributionServer = configuration.GetValueOrDefault(nameof(StaticFilesServerConfiguration.IsDistributionNode), false);
|
||||||
_basePath = configuration.GetValue<string>(nameof(StaticFilesServerConfiguration.CacheDirectory));
|
_basePath = configuration.GetValue<string>(nameof(StaticFilesServerConfiguration.CacheDirectory));
|
||||||
_httpClient = new();
|
_httpClient = new();
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ public class MainFileCleanupService : IHostedService
|
|||||||
private readonly IServiceProvider _services;
|
private readonly IServiceProvider _services;
|
||||||
private CancellationTokenSource _cleanupCts;
|
private CancellationTokenSource _cleanupCts;
|
||||||
|
|
||||||
public MainFileCleanupService(MareMetrics metrics, ILogger<MainFileCleanupService> logger, IServiceProvider services, IConfigurationService<StaticFilesServerConfiguration> configuration)
|
public MainFileCleanupService(MareMetrics metrics, ILogger<MainFileCleanupService> logger,
|
||||||
|
IServiceProvider services, IConfigurationService<StaticFilesServerConfiguration> configuration)
|
||||||
{
|
{
|
||||||
_metrics = metrics;
|
_metrics = metrics;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
@@ -54,11 +55,11 @@ public class MainFileCleanupService : IHostedService
|
|||||||
{
|
{
|
||||||
_logger.LogError(e, "Error during cleanup task");
|
_logger.LogError(e, "Error during cleanup task");
|
||||||
}
|
}
|
||||||
|
var cleanupCheckMinutes = _configuration.GetValueOrDefault(nameof(StaticFilesServerConfiguration.CleanupCheckInMinutes), 15);
|
||||||
var now = DateTime.Now;
|
var now = DateTime.Now;
|
||||||
TimeOnly currentTime = new(now.Hour, now.Minute, now.Second);
|
TimeOnly currentTime = new(now.Hour, now.Minute, now.Second);
|
||||||
TimeOnly futureTime = new(now.Hour, now.Minute - now.Minute % 30, 0);
|
TimeOnly futureTime = new(now.Hour, now.Minute - now.Minute % cleanupCheckMinutes, 0);
|
||||||
var span = futureTime.AddMinutes(30) - currentTime;
|
var span = futureTime.AddMinutes(cleanupCheckMinutes) - currentTime;
|
||||||
|
|
||||||
_logger.LogInformation("File Cleanup Complete, next run at {date}", now.Add(span));
|
_logger.LogInformation("File Cleanup Complete, next run at {date}", now.Add(span));
|
||||||
await Task.Delay(span, ct).ConfigureAwait(false);
|
await Task.Delay(span, ct).ConfigureAwait(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user