test(workers): prove clock and restart safety
CI and Deploy / test (pull_request) Successful in 5m13s
CI and Deploy / deploy (pull_request) Has been skipped

This commit is contained in:
cesnimda
2026-08-15 20:18:02 +02:00
parent a08ba9b45d
commit dbf28b97ce
7 changed files with 124 additions and 36 deletions
@@ -10,7 +10,8 @@ public sealed class FollowUpReminderHostedService(
IConfiguration configuration,
ILogger<FollowUpReminderHostedService> logger,
IStartupReadiness startupReadiness,
ExternalOrigin externalOrigin) : BackgroundService
ExternalOrigin externalOrigin,
TimeProvider timeProvider) : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
@@ -21,11 +22,11 @@ public sealed class FollowUpReminderHostedService(
return;
}
await Task.Delay(TimeSpan.FromSeconds(10), stoppingToken);
await Task.Delay(TimeSpan.FromSeconds(10), timeProvider, stoppingToken);
while (!stoppingToken.IsCancellationRequested)
{
await RunOnceAsync(stoppingToken);
await Task.Delay(TimeSpan.FromHours(6), stoppingToken);
await Task.Delay(TimeSpan.FromHours(6), timeProvider, stoppingToken);
}
}
@@ -45,7 +46,7 @@ public sealed class FollowUpReminderHostedService(
var users = services.GetRequiredService<UserManager<ApplicationUser>>();
var email = services.GetRequiredService<IAppEmailSender>();
var settings = await RulesEngine.GetSettings(db, cancellationToken);
var now = DateTime.Now;
var now = timeProvider.GetLocalNow().DateTime;
var lookAheadDays = Math.Clamp(configuration.GetValue("Email:FollowUpReminders:UpcomingDays", 2), 1, 14);
var upcomingTo = now.AddDays(lookAheadDays);
var lastMessages = await db.Correspondences.AsNoTracking()