diff --git a/services/domain/Big.Application/ExpireRegistrationWorker.cs b/services/domain/Big.Application/ExpireRegistrationWorker.cs index a1acc28..b351355 100644 --- a/services/domain/Big.Application/ExpireRegistrationWorker.cs +++ b/services/domain/Big.Application/ExpireRegistrationWorker.cs @@ -31,6 +31,14 @@ public sealed class ExpireRegistrationWorker(IRegistrationStore store, IAclClien if (registration.Status is not (RegistrationStatus.Ingediend or RegistrationStatus.InBehandeling)) return; + // Cancel the ZGW zaak before advancing the aggregate (mirrors the approval path): if the ACL + // call fails it throws, the aggregate stays open, and the job is redelivered (§8.6) — rather + // than leaving the aggregate VERLOPEN while the zaak stays open. The status guard above stops a + // redelivered job from cancelling the zaak twice (a second resultaat would be a 400). A + // registration expired before its zaak was opened has nothing to cancel. + if (registration.ZaakUrl is not null) + await acl.CancelZaakAsync(registration.ZaakUrl, ct); + registration.Expire(); await store.SaveAsync(registration, ct); }