This commit is contained in:
@@ -15,7 +15,12 @@ internal sealed class DevelopmentTenantDomainLifecycleHostedService(
|
||||
{
|
||||
if (!options.EnableDevelopmentLocalhostBypass) return;
|
||||
|
||||
var interval = TimeSpan.FromSeconds(Math.Clamp(options.PollSeconds, 1, 3600));
|
||||
var activeInterval = TimeSpan.FromSeconds(Math.Clamp(options.PollSeconds, 1, 3600));
|
||||
var maxIdleInterval = TimeSpan.FromSeconds(Math.Clamp(
|
||||
options.MaxIdlePollSeconds,
|
||||
(int)activeInterval.TotalSeconds,
|
||||
3600));
|
||||
var consecutiveIdleIterations = 0;
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
@@ -26,6 +31,7 @@ internal sealed class DevelopmentTenantDomainLifecycleHostedService(
|
||||
var processed = await scope.ServiceProvider
|
||||
.GetRequiredService<ITenantDomainLifecycleService>()
|
||||
.ProcessPendingAsync(stoppingToken);
|
||||
consecutiveIdleIterations = processed == 0 ? consecutiveIdleIterations + 1 : 0;
|
||||
if (processed > 0)
|
||||
logger.LogInformation("Processed {DomainCount} pending Development tenant domains.", processed);
|
||||
}
|
||||
@@ -35,10 +41,25 @@ internal sealed class DevelopmentTenantDomainLifecycleHostedService(
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
consecutiveIdleIterations++;
|
||||
logger.LogError(exception, "Development tenant domain lifecycle iteration failed.");
|
||||
}
|
||||
|
||||
await Task.Delay(interval, stoppingToken);
|
||||
await Task.Delay(
|
||||
CalculateDelay(activeInterval, maxIdleInterval, consecutiveIdleIterations),
|
||||
stoppingToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static TimeSpan CalculateDelay(
|
||||
TimeSpan activeInterval,
|
||||
TimeSpan maxIdleInterval,
|
||||
int consecutiveIdleIterations)
|
||||
{
|
||||
if (consecutiveIdleIterations <= 1) return activeInterval;
|
||||
|
||||
var shift = Math.Min(consecutiveIdleIterations - 1, 20);
|
||||
var delayTicks = activeInterval.Ticks * (1L << shift);
|
||||
return TimeSpan.FromTicks(Math.Min(delayTicks, maxIdleInterval.Ticks));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user