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
+6 -5
View File
@@ -8,7 +8,8 @@ public sealed class RulesHostedService(
BackgroundTenantRunner tenants,
IConfiguration configuration,
ILogger<RulesHostedService> logger,
IStartupReadiness startupReadiness) : BackgroundService
IStartupReadiness startupReadiness,
TimeProvider timeProvider) : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
@@ -19,11 +20,11 @@ public sealed class RulesHostedService(
return;
}
await Task.Delay(TimeSpan.FromSeconds(2), stoppingToken);
await Task.Delay(TimeSpan.FromSeconds(2), timeProvider, stoppingToken);
while (!stoppingToken.IsCancellationRequested)
{
await RunOnceAsync(stoppingToken);
await Task.Delay(TimeSpan.FromMinutes(30), stoppingToken);
await Task.Delay(TimeSpan.FromMinutes(30), timeProvider, stoppingToken);
}
}
@@ -35,11 +36,11 @@ public sealed class RulesHostedService(
return tenants.RunForJobOwnersAsync("rules", ProcessOwnerAsync, cancellationToken);
}
private static async Task ProcessOwnerAsync(IServiceProvider services, CancellationToken cancellationToken)
private async Task ProcessOwnerAsync(IServiceProvider services, CancellationToken cancellationToken)
{
var db = services.GetRequiredService<JobTrackerContext>();
var settings = await RulesEngine.GetSettings(db, cancellationToken);
var now = DateTime.Now;
var now = timeProvider.GetLocalNow().DateTime;
var lastMessages = await db.Correspondences
.GroupBy(message => message.JobApplicationId)
.Select(group => new { JobApplicationId = group.Key, Last = group.Max(x => x.Date) })