Merge branch 'main' of https://git.stella-ops.org/stella-ops.org/git.stella-ops.org
This commit is contained in:
@@ -19,6 +19,7 @@ public sealed class CacheWarmupHostedService : BackgroundService
|
||||
private readonly IAdvisoryCacheService _cacheService;
|
||||
private readonly ConcelierCacheOptions _options;
|
||||
private readonly ILogger<CacheWarmupHostedService>? _logger;
|
||||
private readonly Func<double> _jitterSource;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="CacheWarmupHostedService"/>.
|
||||
@@ -26,11 +27,13 @@ public sealed class CacheWarmupHostedService : BackgroundService
|
||||
public CacheWarmupHostedService(
|
||||
IAdvisoryCacheService cacheService,
|
||||
IOptions<ConcelierCacheOptions> options,
|
||||
ILogger<CacheWarmupHostedService>? logger = null)
|
||||
ILogger<CacheWarmupHostedService>? logger = null,
|
||||
Func<double>? jitterSource = null)
|
||||
{
|
||||
_cacheService = cacheService;
|
||||
_options = options.Value;
|
||||
_logger = logger;
|
||||
_jitterSource = jitterSource ?? Random.Shared.NextDouble;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -66,7 +69,7 @@ public sealed class CacheWarmupHostedService : BackgroundService
|
||||
}
|
||||
}
|
||||
|
||||
private static TimeSpan ResolveWarmupDelay(ConcelierCacheOptions options)
|
||||
private TimeSpan ResolveWarmupDelay(ConcelierCacheOptions options)
|
||||
{
|
||||
var delay = options.WarmupDelay;
|
||||
var jitter = options.WarmupDelayJitter;
|
||||
@@ -76,7 +79,7 @@ public sealed class CacheWarmupHostedService : BackgroundService
|
||||
return delay;
|
||||
}
|
||||
|
||||
var jitterMillis = Random.Shared.NextDouble() * jitter.TotalMilliseconds;
|
||||
var jitterMillis = _jitterSource() * jitter.TotalMilliseconds;
|
||||
return delay + TimeSpan.FromMilliseconds(jitterMillis);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user