feat(domain): Quartz cron job fires the herregistratie sweep; expose deadline on read (refs #18)
HerregistratieReminderJob (Quartz IJob) fires HerregistratieReminderSweep on a
daily cron wired in Big.Api (overridable via Quartz__Cron), and logs how many
reminders went out. Quartz.NET is used for this time-triggered fleet sweep,
distinct from the queue-draining pumps (ADR-0022). GET /registrations/{id} now
returns herregistratieVoor + herregistratieReminderVerstuurd. The scheduling
shell is excluded from mutation, mirroring the pumps.
refs #18
This commit is contained in:
@@ -5,6 +5,10 @@
|
||||
<ProjectReference Include="..\Big.Infrastructure\Big.Infrastructure.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Quartz.Extensions.Hosting" Version="3.18.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Big.Application;
|
||||
using Big.Domain;
|
||||
using Big.Infrastructure;
|
||||
using Quartz;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
@@ -40,6 +41,7 @@ builder.Services.AddScoped<OpenZaakJobProcessor>();
|
||||
builder.Services.AddScoped<BeoordelingEscalatieProcessor>();
|
||||
builder.Services.AddScoped<ExpireRegistrationWorker>();
|
||||
builder.Services.AddScoped<RegistratieVerlopenProcessor>();
|
||||
builder.Services.AddScoped<HerregistratieReminderSweep>();
|
||||
|
||||
// The hosted external-task job worker polls Flowable and drives OpenZaakAanmaken to completion.
|
||||
builder.Services.AddHostedService<OpenZaakJobPump>();
|
||||
@@ -50,6 +52,19 @@ builder.Services.AddHostedService<BeoordelingEscalatiePump>();
|
||||
// parks and expires each lapsed registration to VERLOPEN (S-10a, ADR-0017).
|
||||
builder.Services.AddHostedService<RegistratieVerlopenPump>();
|
||||
|
||||
// The herregistratie reminder sweep runs on a daily cron via Quartz.NET (S-17, ADR-0022) — a
|
||||
// time-triggered fleet sweep, deliberately a different mechanism from the queue-draining pumps above.
|
||||
// The cron is overridable with Quartz__Cron; it defaults to 03:00 daily.
|
||||
builder.Services.AddQuartz(q =>
|
||||
{
|
||||
var jobKey = new JobKey("herregistratie-reminder");
|
||||
q.AddJob<HerregistratieReminderJob>(jobKey);
|
||||
q.AddTrigger(t => t
|
||||
.ForJob(jobKey)
|
||||
.WithCronSchedule(builder.Configuration["Quartz:Cron"] ?? "0 0 3 * * ?"));
|
||||
});
|
||||
builder.Services.AddQuartzHostedService(o => o.WaitForJobsToComplete = true);
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.MapGet("/health", () => "Healthy");
|
||||
@@ -169,7 +184,8 @@ app.MapGet("/registrations/{id}", async (string id, IRegistrationStore store, Ca
|
||||
return registration is null
|
||||
? Results.NotFound()
|
||||
: Results.Ok(new RegistrationResponse(
|
||||
registration.Id.ToString(), registration.Status.ToString(), registration.ZaakUrl?.ToString()));
|
||||
registration.Id.ToString(), registration.Status.ToString(), registration.ZaakUrl?.ToString(),
|
||||
registration.HerregistratieVoor?.ToString("O"), registration.HerregistratieReminderVerstuurd));
|
||||
});
|
||||
|
||||
await app.RunAsync();
|
||||
@@ -182,6 +198,11 @@ public sealed record WithdrawRequest(string Bsn);
|
||||
|
||||
public sealed record ProvideDocumentsRequest(string Bsn, string ContentBase64, string? FileName = null, string? ContentType = null);
|
||||
|
||||
public sealed record RegistrationResponse(string RegistrationId, string Status, string? ZaakUrl);
|
||||
public sealed record RegistrationResponse(
|
||||
string RegistrationId,
|
||||
string Status,
|
||||
string? ZaakUrl,
|
||||
string? HerregistratieVoor = null,
|
||||
bool HerregistratieReminderVerstuurd = false);
|
||||
|
||||
public partial class Program;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.0" />
|
||||
<PackageReference Include="Quartz" Version="3.18.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using Big.Application;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Quartz;
|
||||
|
||||
namespace Big.Infrastructure;
|
||||
|
||||
/// <summary>
|
||||
/// The Quartz job that fires the herregistratie reminder sweep on a cron schedule (S-17, ADR-0022).
|
||||
/// A deliberately thin shell — it resolves the pure <see cref="HerregistratieReminderSweep"/> (Quartz's
|
||||
/// MS-DI job factory gives each fire its own scope) and logs how many reminders went out; all the
|
||||
/// sweep logic is unit-tested in the application layer. Quartz drives this — rather than a
|
||||
/// BackgroundService poll loop like the pumps — because it is a time-triggered fleet sweep, not a
|
||||
/// queue to drain (the distinction recorded in ADR-0022). <see cref="DisallowConcurrentExecutionAttribute"/>
|
||||
/// stops a slow sweep overlapping the next fire against the shared store.
|
||||
/// </summary>
|
||||
[DisallowConcurrentExecution]
|
||||
public sealed class HerregistratieReminderJob(
|
||||
HerregistratieReminderSweep sweep, ILogger<HerregistratieReminderJob> logger) : IJob
|
||||
{
|
||||
public async Task Execute(IJobExecutionContext context)
|
||||
{
|
||||
var reminded = await sweep.SweepAsync(context.CancellationToken);
|
||||
logger.LogInformation(
|
||||
"Herregistratie-sweep voltooid: {Count} herinnering(en) verstuurd.", reminded.Count);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,8 @@
|
||||
"mutate": [
|
||||
"!**/OpenZaakJobPump.cs",
|
||||
"!**/BeoordelingEscalatiePump.cs",
|
||||
"!**/RegistratieVerlopenPump.cs"
|
||||
"!**/RegistratieVerlopenPump.cs",
|
||||
"!**/HerregistratieReminderJob.cs"
|
||||
],
|
||||
"thresholds": {
|
||||
"high": 95,
|
||||
|
||||
@@ -40,7 +40,7 @@ public sealed class EenRegistratieBeoordelenSteps
|
||||
|
||||
[When("the behandelaar decides \"(.*)\"")]
|
||||
public async Task WhenTheBehandelaarDecides(string besluit)
|
||||
=> await new BeoordeelRegistratie(_store, _acl, _tasks).HandleAsync(
|
||||
=> await new BeoordeelRegistratie(_store, _acl, _tasks, TimeProvider.System).HandleAsync(
|
||||
new BeoordeelRegistratieCommand(_id, Enum.Parse<BeoordelingsBesluit>(besluit, ignoreCase: true)));
|
||||
|
||||
[Then("the registration has status \"(.*)\"")]
|
||||
|
||||
@@ -221,4 +221,9 @@ public sealed class InMemoryRegistrationStore : IRegistrationStore
|
||||
public Task<Registration?> FindOpenByBsnAsync(string bsn, CancellationToken ct = default)
|
||||
=> Task.FromResult(_byId.Values.FirstOrDefault(r =>
|
||||
r.Bsn == bsn && r.Status is RegistrationStatus.Ingediend or RegistrationStatus.InBehandeling));
|
||||
|
||||
public Task<IReadOnlyList<Registration>> FindDueForHerregistratieReminderAsync(
|
||||
DateTimeOffset asOf, CancellationToken ct = default)
|
||||
=> Task.FromResult<IReadOnlyList<Registration>>(
|
||||
_byId.Values.Where(r => r.HerregistratieReminderDue(asOf)).ToList());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user