## What & why S-10a, the **workflow/timeout spine** of the (split) document-upload slice: the registratie process now parks at a **`WachtOpDocumenten`** user task with an **interrupting `P30D` boundary timer**. When the documents arrive the task completes and the process continues into the diploma routing (S-13) → Beoordelen; if the 30 days lapse, the timer cancels the wait, runs a `RegistratieVerlopen` external-worker task, and the domain expires the aggregate to a new terminal status **`Verlopen`**. Backend only — the real upload trigger (portal → BFF → ACL → Documenten API) is S-10b (#103). Closes #102 Mechanism recorded in **ADR-0017**; opened as proposal #104. Mirrors the S-14 escalation (boundary-timer + external-worker) and S-11 withdrawal (interrupting cancel) patterns. ## Definition of Done - [x] Linked Gitea issue (above). - [x] Failing test committed before the implementation (red→green pairs per layer). - [x] Implementation makes the test pass. - [x] Conventional Commits referencing the issue (`refs #102`). - [ ] CI green — all Gitea Actions jobs (pending on this PR). - [x] `docker compose up` health unaffected (no new services; deploy path unchanged). - [x] Docs updated (ADR-0017, demo-script, BACKLOG split). - [x] ADR added (`docs/architecture/adr-0017-document-wait-timeout-cancellation.md`). - [x] Demo note in `docs/demo-script.md`. ## Notes for reviewers - **Domain** (`Registration.Expire()` + `Verlopen`), **application** (`ExpireRegistrationWorker`), **infra** (`RegistratieVerlopenProcessor`/`Pump`, `IRegistratieVerlopenClient`, Flowable acquire/complete + `CompleteDocumentWaitAsync`) — the timeout counterpart to the OpenZaak/escalation worker trios; idempotent per §8.6. - **BPMN** verified live against a `flowable-rest` probe: complete `WachtOpDocumenten` → routes to Beoordelen; fire the P30D timer → `RegistratieVerlopen` job (carrying `registrationId`) + the wait task cancelled. `verify-domain` exercises both branches in-stack (completes the wait in every existing block; fires the timer and asserts `Verlopen` in a new block). - **Scope boundary:** on expiry the aggregate goes `Verlopen` and the process ends, but the ZGW *zaak* is not yet set to a cancellation status — that needs a new ACL method + statustype seeding and is folded into S-10b (noted in ADR-0017). - `CompleteDocumentWaitAsync` is built and HTTP-tested here but not yet called from a domain endpoint; S-10b wires the upload trigger to it. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Reviewed-on: #105
205 lines
8.8 KiB
C#
205 lines
8.8 KiB
C#
using Big.Application;
|
|
using Big.Domain;
|
|
using Big.Infrastructure;
|
|
|
|
namespace Acceptance.Support;
|
|
|
|
/// <summary>An in-memory Workflow Client for the domain acceptance scenario: it records which
|
|
/// registration a process was started for and returns a fixed instance id. The acceptance test
|
|
/// drives the use case without a running Flowable (live verification is the verify-domain check).</summary>
|
|
public sealed class InMemoryWorkflowClient : IWorkflowClient
|
|
{
|
|
public const string StartedProcessInstanceId = "proc-acc-1";
|
|
|
|
public RegistrationId? StartedFor { get; private set; }
|
|
public DiplomaOrigin? StartedWithOrigin { get; private set; }
|
|
public string? WithdrawnProcessInstanceId { get; private set; }
|
|
public string? CompletedDocumentWaitFor { get; private set; }
|
|
|
|
public Task<string> StartRegistrationProcessAsync(
|
|
RegistrationId registrationId, DiplomaOrigin diplomaOrigin, CancellationToken ct = default)
|
|
{
|
|
StartedFor = registrationId;
|
|
StartedWithOrigin = diplomaOrigin;
|
|
return Task.FromResult(StartedProcessInstanceId);
|
|
}
|
|
|
|
public Task WithdrawProcessAsync(string processInstanceId, CancellationToken ct = default)
|
|
{
|
|
WithdrawnProcessInstanceId = processInstanceId;
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task CompleteDocumentWaitAsync(string processInstanceId, CancellationToken ct = default)
|
|
{
|
|
CompletedDocumentWaitFor = processInstanceId;
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
/// <summary>An in-memory ACL stand-in: records the bsn it opened a zaak for and returns a fixed URL,
|
|
/// so the scenario verifies the domain crosses the ACL boundary (§8.1) without a running OpenZaak.</summary>
|
|
public sealed class InMemoryAclClient : IAclClient
|
|
{
|
|
public static readonly Uri OpenedZaakUrl = new("http://openzaak/zaken/api/v1/zaken/acc-zaak");
|
|
|
|
public string? OpenedForBsn { get; private set; }
|
|
public string? OpenedWithReference { get; private set; }
|
|
public Uri? ApprovedZaakUrl { get; private set; }
|
|
|
|
public Task<Uri> OpenZaakAsync(string bsn, string reference, CancellationToken ct = default)
|
|
{
|
|
OpenedForBsn = bsn;
|
|
OpenedWithReference = reference;
|
|
return Task.FromResult(OpenedZaakUrl);
|
|
}
|
|
|
|
public Task ApproveZaakAsync(Uri zaakUrl, CancellationToken ct = default)
|
|
{
|
|
ApprovedZaakUrl = zaakUrl;
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
/// <summary>An in-memory user-task client for the beoordeling acceptance scenario: it holds one open
|
|
/// Beoordelen task per registration and records the besluit each is completed with.</summary>
|
|
public sealed class InMemoryUserTaskClient : IUserTaskClient
|
|
{
|
|
private readonly List<BeoordelingTask> _open = [];
|
|
|
|
public (string TaskId, BeoordelingsBesluit Besluit)? Completed { get; private set; }
|
|
|
|
public void Open(RegistrationId registrationId) => _open.Add(new BeoordelingTask($"task-{registrationId}", registrationId));
|
|
|
|
public Task<IReadOnlyList<BeoordelingTask>> GetOpenBeoordelingenAsync(CancellationToken ct = default)
|
|
=> Task.FromResult<IReadOnlyList<BeoordelingTask>>(_open);
|
|
|
|
public Task ClaimAsync(string taskId, string behandelaar, CancellationToken ct = default) => Task.CompletedTask;
|
|
|
|
public Task CompleteBeoordelingAsync(string taskId, BeoordelingsBesluit besluit, CancellationToken ct = default)
|
|
{
|
|
Completed = (taskId, besluit);
|
|
_open.RemoveAll(t => t.TaskId == taskId);
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
/// <summary>An in-memory Flowable stand-in for the beoordeling-escalation scenario (S-14): it models
|
|
/// one Beoordelen task per process instance — its candidate group and whether it is still open — and
|
|
/// the escalation jobs the non-interrupting 14-day boundary timer parks. It drives the escalation
|
|
/// worker's behaviour without a running Flowable; the timer firing live is the verify-domain check.</summary>
|
|
public sealed class InMemoryEscalatieClient : IBeoordelingEscalatieClient
|
|
{
|
|
private sealed class ParkedTask
|
|
{
|
|
public string CandidateGroup { get; set; } = "behandelaar";
|
|
public bool IsOpen { get; set; } = true;
|
|
}
|
|
|
|
private readonly Dictionary<string, ParkedTask> _tasks = [];
|
|
private readonly List<EscalatieJob> _parked = [];
|
|
private int _seq;
|
|
|
|
/// <summary>A registration parks at Beoordelen, claimable by the behandelaar group.</summary>
|
|
public string ParkBeoordeling()
|
|
{
|
|
var pid = $"pi-{++_seq}";
|
|
_tasks[pid] = new ParkedTask();
|
|
return pid;
|
|
}
|
|
|
|
/// <summary>The behandelaar completes the beoordeling before the timer fires: the task closes.</summary>
|
|
public void CompleteBeoordeling(string processInstanceId) => _tasks[processInstanceId].IsOpen = false;
|
|
|
|
/// <summary>The 14-day boundary timer fires: a non-interrupting token parks an escalation job.</summary>
|
|
public void FireEscalationTimer(string processInstanceId)
|
|
=> _parked.Add(new EscalatieJob($"job-{++_seq}", processInstanceId));
|
|
|
|
/// <summary>The candidate group that may currently pick the task up.</summary>
|
|
public string CandidateGroupFor(string processInstanceId) => _tasks[processInstanceId].CandidateGroup;
|
|
|
|
public Task<IReadOnlyList<EscalatieJob>> AcquireBeoordelingEscalatieJobsAsync(int maxJobs, CancellationToken ct = default)
|
|
=> Task.FromResult<IReadOnlyList<EscalatieJob>>(_parked.Take(maxJobs).ToList());
|
|
|
|
public Task ReassignBeoordelingToTeamleadAsync(string processInstanceId, CancellationToken ct = default)
|
|
{
|
|
// No-op if the behandelaar already completed it — the timer/completion race (§8.6).
|
|
var task = _tasks[processInstanceId];
|
|
if (task.IsOpen)
|
|
task.CandidateGroup = "teamlead";
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task CompleteBeoordelingEscalatieJobAsync(string jobId, CancellationToken ct = default)
|
|
{
|
|
_parked.RemoveAll(j => j.JobId == jobId);
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
/// <summary>An in-memory Flowable stand-in for the document-timeout scenario (S-10a): it models one
|
|
/// WachtOpDocumenten wait per process instance — whether it is still open and the registration it
|
|
/// correlates to — and the RegistratieVerlopen jobs the interrupting 30-day boundary timer parks. It
|
|
/// drives the timeout worker's behaviour without a running Flowable; the timer firing live is the
|
|
/// verify-domain check.</summary>
|
|
public sealed class InMemoryDocumentTimeoutClient : IRegistratieVerlopenClient
|
|
{
|
|
private sealed class Wait
|
|
{
|
|
public required RegistrationId RegistrationId { get; init; }
|
|
public bool IsWaiting { get; set; } = true;
|
|
}
|
|
|
|
private readonly Dictionary<string, Wait> _waits = [];
|
|
private readonly List<RegistratieVerlopenJob> _parked = [];
|
|
private int _seq;
|
|
|
|
/// <summary>A registration parks at WachtOpDocumenten, waiting for the citizen's documents.</summary>
|
|
public string ParkWaitingForDocuments(RegistrationId registrationId)
|
|
{
|
|
var pid = $"pi-{++_seq}";
|
|
_waits[pid] = new Wait { RegistrationId = registrationId };
|
|
return pid;
|
|
}
|
|
|
|
/// <summary>The documents arrive before the timer fires: the wait task closes, so the interrupting
|
|
/// timer no longer fires (mirrors the Workflow Client completing WachtOpDocumenten).</summary>
|
|
public void ReceiveDocuments(string processInstanceId) => _waits[processInstanceId].IsWaiting = false;
|
|
|
|
/// <summary>The 30-day interrupting boundary timer fires: if still waiting, it cancels the wait and
|
|
/// parks a RegistratieVerlopen job carrying the correlated registration id. A no-op if the documents
|
|
/// already arrived (the wait/timer race, §8.6).</summary>
|
|
public void FireDocumentTimer(string processInstanceId)
|
|
{
|
|
var wait = _waits[processInstanceId];
|
|
if (!wait.IsWaiting)
|
|
return;
|
|
wait.IsWaiting = false;
|
|
_parked.Add(new RegistratieVerlopenJob($"job-{++_seq}", wait.RegistrationId));
|
|
}
|
|
|
|
public Task<IReadOnlyList<RegistratieVerlopenJob>> AcquireRegistratieVerlopenJobsAsync(int maxJobs, CancellationToken ct = default)
|
|
=> Task.FromResult<IReadOnlyList<RegistratieVerlopenJob>>(_parked.Take(maxJobs).ToList());
|
|
|
|
public Task CompleteRegistratieVerlopenJobAsync(string jobId, CancellationToken ct = default)
|
|
{
|
|
_parked.RemoveAll(j => j.JobId == jobId);
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
/// <summary>An in-memory registration store for the domain acceptance scenario.</summary>
|
|
public sealed class InMemoryRegistrationStore : IRegistrationStore
|
|
{
|
|
private readonly Dictionary<RegistrationId, Registration> _byId = [];
|
|
|
|
public Task SaveAsync(Registration registration, CancellationToken ct = default)
|
|
{
|
|
_byId[registration.Id] = registration;
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task<Registration?> GetAsync(RegistrationId id, CancellationToken ct = default)
|
|
=> Task.FromResult(_byId.GetValueOrDefault(id));
|
|
}
|