Compare commits
3 Commits
feat/7-eve
...
cc9e7852e1
| Author | SHA1 | Date | |
|---|---|---|---|
| cc9e7852e1 | |||
| c9edf27a48 | |||
| c3ccffe417 |
88
docs/architecture/adr-0009-external-task-job-worker.md
Normal file
88
docs/architecture/adr-0009-external-task-job-worker.md
Normal file
@@ -0,0 +1,88 @@
|
||||
# ADR-0009: The Domain Service drives Flowable as an external-task job worker
|
||||
|
||||
- **Status:** Accepted
|
||||
- **Date:** 2026-06-30
|
||||
- **Deciders:** Respellion engineering
|
||||
- **Relates to:** S-05 (#6); proposal #60; builds on ADR-0001 (loose coupling, §8.1/§8.2), S-03 (#4, the `registratie` BPMN), S-04 (#5, the ACL `OpenZaak` operation)
|
||||
|
||||
## Context
|
||||
|
||||
S-05 (#6) adds the **BIG Domain Service**. Submitting a registration must: create a
|
||||
`Registration` aggregate, **start the Flowable `registratie` process** (S-03), have the
|
||||
`OpenZaakAanmaken` task **open a zaak via the ACL** (S-04), and store the resulting zaak URL
|
||||
back on the aggregate.
|
||||
|
||||
`OpenZaakAanmaken` is a Flowable **external-worker** service task (`flowable:type="external-worker"`,
|
||||
topic `OpenZaakAanmaken`). Flowable does not push it anywhere — it parks the job and waits for a
|
||||
worker to **acquire and lock** it, do the work, and **complete** it. Two coupling rules constrain
|
||||
who may do what:
|
||||
|
||||
- **§8.2 — the Workflow Client is the only code that talks to Flowable.** BPMN models never embed
|
||||
OpenZaak knowledge; they ask the Workflow Client to execute external tasks.
|
||||
- **§8.1 — the ACL is the only code that talks to ZGW.** The worker opens the zaak *through the ACL*,
|
||||
never by constructing ZGW URLs itself.
|
||||
|
||||
This is an ADR-worthy moment (§14): a service boundary is defined and both coupling rules are
|
||||
exercised. The open question is *how* the external task is driven.
|
||||
|
||||
## Decision
|
||||
|
||||
**The Domain Service drives the `OpenZaakAanmaken` task as a hosted external-task job worker
|
||||
(PRD §36). Orchestration is eventually consistent, not request-synchronous.**
|
||||
|
||||
- **`POST /registrations` is fast and side-effecting only on the domain side.** It creates the
|
||||
`Registration` aggregate in state `INGEDIEND`, persists it, and asks the Workflow Client to start
|
||||
one `registratie` process instance, recording the process-instance id on the aggregate. It returns
|
||||
immediately; it does **not** wait for the zaak to be opened.
|
||||
- **A hosted worker polls Flowable for `OpenZaakAanmaken` jobs.** It acquires and locks a job, calls
|
||||
the ACL `OpenZaak` operation (§8.1), attaches the returned zaak URL to the matching aggregate
|
||||
(`Registration.AttachZaak`), and completes the job in Flowable. The process then runs to its end
|
||||
event.
|
||||
- **The Workflow Client is the only Flowable client (§8.2).** It lives in the Domain Service's
|
||||
`Infrastructure` layer and speaks Flowable's REST API (start process-instance; acquire/lock/complete
|
||||
external-worker jobs). No other code — not the Application layer, not the BPMN — knows Flowable
|
||||
exists.
|
||||
- **The worker *logic* is an Application service over ports**, not Flowable-aware code. `OpenZaakWorker`
|
||||
takes an acquired job (topic + the registration id it carries), calls `IAclClient` and
|
||||
`IRegistrationStore`, and returns the zaak URL to complete with. The **polling loop** is a thin
|
||||
`BackgroundService` in `Infrastructure` that fetches jobs via the Workflow Client and feeds them to
|
||||
the worker. So the orchestration is covered by fast unit tests against fakes; only the REST framing
|
||||
needs a container integration test.
|
||||
|
||||
## Scope decisions for the minimal slice
|
||||
|
||||
- **Registration persistence is in-memory.** The walking skeleton's *read* path is fed by
|
||||
NRC → Event Subscriber → projection (S-06, #7), not by the domain database. An EF-backed domain
|
||||
store buys nothing the demo needs yet, so it is a documented follow-up; the `IRegistrationStore`
|
||||
port keeps that change additive. (PRD §88 envisions EF Core for the domain DB eventually.)
|
||||
- **The aggregate's state machine is minimal:** `INGEDIEND` on submission. Later flows (withdrawal,
|
||||
beoordeling, herregistratie) add states in their own slices — they are out of scope here.
|
||||
- **No bsn flows to ZGW yet.** The ACL `OpenZaak` operation already default-fills the ZGW-mandatory
|
||||
fields (ADR-0003) and takes the bsn as its domain payload; the domain hands it through unchanged.
|
||||
|
||||
## Consequences
|
||||
|
||||
- **Positive:** the submit request is decoupled from ACL/OpenZaak latency; the documented Common
|
||||
Ground pattern (external-task worker) is realised; both coupling rules (§8.1, §8.2) hold with the
|
||||
Flowable knowledge isolated to one Infrastructure class; the orchestration is unit-testable.
|
||||
- **Negative / deferred:**
|
||||
- Eventual consistency: immediately after `POST /registrations` the aggregate has no zaak URL yet.
|
||||
Acceptable — the read side is the projection, not the domain store.
|
||||
- In-memory registration state is lost on restart; fine for the skeleton, replaced by an EF store
|
||||
in a follow-up.
|
||||
- The worker polls (no push); poll interval is a tuning knob, not a correctness concern, since
|
||||
Flowable holds the job until completed.
|
||||
|
||||
## Alternatives considered
|
||||
|
||||
- **Synchronous acquire+complete inside the `POST /registrations` request** — rejected: simpler and
|
||||
deterministic, but couples the submit request to ACL/OpenZaak latency and failure, and is not the
|
||||
external-task worker pattern PRD §36 mandates. It would also make the request fail if OpenZaak is
|
||||
briefly down, instead of the job simply staying parked for the worker to retry.
|
||||
- **A standalone Workflow Client service, separate from the Domain Service** — rejected for this
|
||||
slice: the worker needs the domain's aggregate store and the ACL client anyway, and PRD §9 places
|
||||
the Workflow Client inside the Domain Service deployment. A separate process adds a hop and a
|
||||
shared store for no current benefit.
|
||||
- **Flowable pushes to a webhook instead of being polled** — rejected: Flowable's external-worker
|
||||
model is pull-based (acquire/lock/complete); a push shim would re-implement it with weaker
|
||||
delivery guarantees.
|
||||
@@ -30,6 +30,7 @@ nav:
|
||||
- "ADR-0006: ACL integration test provisioning": architecture/adr-0006-integration-test-provisioning.md
|
||||
- "ADR-0007: OpenZaak → NRC notification wiring": architecture/adr-0007-notification-wiring.md
|
||||
- "ADR-0008: Read projection store": architecture/adr-0008-read-projection-store.md
|
||||
- "ADR-0009: External-task job worker": architecture/adr-0009-external-task-job-worker.md
|
||||
- Working in Gitea: gitea-workflow.md
|
||||
- Demo script: demo-script.md
|
||||
- Runbooks:
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
<Project Path="services/acl/Acl.IntegrationTests/Acl.IntegrationTests.csproj" />
|
||||
<Project Path="services/acl/Acl.Tests/Acl.Tests.csproj" />
|
||||
</Folder>
|
||||
<Folder Name="/services/domain/">
|
||||
<Project Path="services/domain/Big.Domain/Big.Domain.csproj" />
|
||||
<Project Path="services/domain/Big.Tests/Big.Tests.csproj" />
|
||||
</Folder>
|
||||
<Folder Name="/services/bff/">
|
||||
<Project Path="services/bff/Bff.Api/Bff.Api.csproj" />
|
||||
<Project Path="services/bff/Bff.Tests/Bff.Tests.csproj" />
|
||||
|
||||
11
services/domain/Big.Domain/Big.Domain.csproj
Normal file
11
services/domain/Big.Domain/Big.Domain.csproj
Normal file
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<!-- The domain layer (CLAUDE.md §9): aggregates, value objects, invariants.
|
||||
Pure C# — no external dependencies, no infrastructure concerns. -->
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
47
services/domain/Big.Domain/Registration.cs
Normal file
47
services/domain/Big.Domain/Registration.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
namespace Big.Domain;
|
||||
|
||||
/// <summary>
|
||||
/// The Registration aggregate root (CLAUDE.md §2.2): a zorgprofessional's submission to the BIG
|
||||
/// register. It owns its lifecycle invariants — it starts <see cref="RegistrationStatus.Ingediend"/>
|
||||
/// on submission, remembers the Flowable process that drives it, and records the zaak the ACL opens.
|
||||
/// </summary>
|
||||
public sealed class Registration
|
||||
{
|
||||
// STUB (red): mutators are no-ops and Submit leaves the bsn empty so the behaviour tests
|
||||
// compile and fail on their assertions. The green commit implements the invariants.
|
||||
private Registration(RegistrationId id, string bsn)
|
||||
{
|
||||
Id = id;
|
||||
Bsn = bsn;
|
||||
Status = RegistrationStatus.Ingediend;
|
||||
}
|
||||
|
||||
public RegistrationId Id { get; }
|
||||
|
||||
/// <summary>The citizen-service number of the submitting zorgprofessional. Handed to the ACL
|
||||
/// as the domain payload; the domain never constructs ZGW concepts from it (§8.1).</summary>
|
||||
public string Bsn { get; }
|
||||
|
||||
public RegistrationStatus Status { get; private set; }
|
||||
|
||||
/// <summary>The Flowable process instance driving this registration, once started.</summary>
|
||||
public string? ProcessInstanceId { get; private set; }
|
||||
|
||||
/// <summary>The zaak the ACL opened for this registration, once the external task has run.</summary>
|
||||
public Uri? ZaakUrl { get; private set; }
|
||||
|
||||
/// <summary>Submit a new registration. It begins in <see cref="RegistrationStatus.Ingediend"/>.</summary>
|
||||
public static Registration Submit(string bsn) => new(RegistrationId.New(), string.Empty);
|
||||
|
||||
/// <summary>Record that the registratie workflow process has been started for this registration.</summary>
|
||||
public void RecordProcessStarted(string processInstanceId)
|
||||
{
|
||||
// STUB (red).
|
||||
}
|
||||
|
||||
/// <summary>Attach the zaak the ACL opened. Idempotent on the same URL; a conflicting URL is rejected.</summary>
|
||||
public void AttachZaak(Uri zaakUrl)
|
||||
{
|
||||
// STUB (red).
|
||||
}
|
||||
}
|
||||
15
services/domain/Big.Domain/RegistrationId.cs
Normal file
15
services/domain/Big.Domain/RegistrationId.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace Big.Domain;
|
||||
|
||||
/// <summary>The identity of a <see cref="Registration"/> aggregate — opaque, server-assigned,
|
||||
/// and distinct from the OpenZaak zaak id (which the projection keys on). A value object so the
|
||||
/// id can travel as a Flowable process variable and back without ever being a bare string.</summary>
|
||||
public readonly record struct RegistrationId(Guid Value)
|
||||
{
|
||||
/// <summary>Mint a fresh identity for a newly submitted registration.</summary>
|
||||
public static RegistrationId New() => new(Guid.NewGuid());
|
||||
|
||||
/// <summary>Rehydrate an id carried as a string (e.g. a Flowable process variable).</summary>
|
||||
public static RegistrationId Parse(string value) => new(Guid.Parse(value));
|
||||
|
||||
public override string ToString() => Value.ToString();
|
||||
}
|
||||
10
services/domain/Big.Domain/RegistrationStatus.cs
Normal file
10
services/domain/Big.Domain/RegistrationStatus.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Big.Domain;
|
||||
|
||||
/// <summary>The lifecycle states a <see cref="Registration"/> moves through. The walking
|
||||
/// skeleton knows only <see cref="Ingediend"/>; withdrawal, beoordeling and herregistratie
|
||||
/// states arrive in their own slices (Iteration 2+).</summary>
|
||||
public enum RegistrationStatus
|
||||
{
|
||||
/// <summary>Submitted by the zorgprofessional; the registratie process has been started.</summary>
|
||||
Ingediend,
|
||||
}
|
||||
25
services/domain/Big.Tests/Big.Tests.csproj
Normal file
25
services/domain/Big.Tests/Big.Tests.csproj
Normal file
@@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Big.Domain\Big.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
77
services/domain/Big.Tests/RegistrationTests.cs
Normal file
77
services/domain/Big.Tests/RegistrationTests.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using Big.Domain;
|
||||
|
||||
namespace Big.Tests;
|
||||
|
||||
public class RegistrationTests
|
||||
{
|
||||
[Fact]
|
||||
public void Submitting_a_registration_starts_in_ingediend()
|
||||
{
|
||||
var registration = Registration.Submit("123456782");
|
||||
|
||||
Assert.Equal(RegistrationStatus.Ingediend, registration.Status);
|
||||
Assert.Equal("123456782", registration.Bsn);
|
||||
Assert.NotEqual(Guid.Empty, registration.Id.Value);
|
||||
Assert.Null(registration.ZaakUrl);
|
||||
Assert.Null(registration.ProcessInstanceId);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
[InlineData(null)]
|
||||
public void Submitting_without_a_bsn_is_rejected(string? bsn)
|
||||
=> Assert.Throws<ArgumentException>(() => Registration.Submit(bsn!));
|
||||
|
||||
[Fact]
|
||||
public void Recording_the_started_process_keeps_its_instance_id()
|
||||
{
|
||||
var registration = Registration.Submit("123456782");
|
||||
|
||||
registration.RecordProcessStarted("proc-42");
|
||||
|
||||
Assert.Equal("proc-42", registration.ProcessInstanceId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Attaching_a_zaak_records_its_url_and_keeps_the_status_ingediend()
|
||||
{
|
||||
var registration = Registration.Submit("123456782");
|
||||
var zaak = new Uri("http://openzaak/zaken/api/v1/zaken/abc");
|
||||
|
||||
registration.AttachZaak(zaak);
|
||||
|
||||
Assert.Equal(zaak, registration.ZaakUrl);
|
||||
Assert.Equal(RegistrationStatus.Ingediend, registration.Status);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Attaching_a_null_zaak_is_rejected()
|
||||
{
|
||||
var registration = Registration.Submit("123456782");
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => registration.AttachZaak(null!));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Re_attaching_the_same_zaak_is_idempotent()
|
||||
{
|
||||
var registration = Registration.Submit("123456782");
|
||||
var zaak = new Uri("http://openzaak/zaken/api/v1/zaken/abc");
|
||||
|
||||
registration.AttachZaak(zaak);
|
||||
registration.AttachZaak(zaak);
|
||||
|
||||
Assert.Equal(zaak, registration.ZaakUrl);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Attaching_a_conflicting_zaak_is_rejected()
|
||||
{
|
||||
var registration = Registration.Submit("123456782");
|
||||
registration.AttachZaak(new Uri("http://openzaak/zaken/api/v1/zaken/abc"));
|
||||
|
||||
Assert.Throws<InvalidOperationException>(
|
||||
() => registration.AttachZaak(new Uri("http://openzaak/zaken/api/v1/zaken/other")));
|
||||
}
|
||||
}
|
||||
4
services/domain/Big.slnx
Normal file
4
services/domain/Big.slnx
Normal file
@@ -0,0 +1,4 @@
|
||||
<Solution>
|
||||
<Project Path="Big.Domain/Big.Domain.csproj" />
|
||||
<Project Path="Big.Tests/Big.Tests.csproj" />
|
||||
</Solution>
|
||||
Reference in New Issue
Block a user