fix:修复部分数据库查询问题
Some checks failed
ci / release-gate (push) Has been cancelled

This commit is contained in:
2026-08-03 14:22:06 +08:00
parent 9f19bea7ee
commit 2c4a0bad6c
8 changed files with 136 additions and 40 deletions

View File

@@ -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));
}
}