test(workers): prove clock and restart safety
This commit is contained in:
@@ -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) })
|
||||
|
||||
Reference in New Issue
Block a user