using Microsoft.Extensions.Logging; namespace Big.Infrastructure; /// /// One poll tick of the beoordeling-escalation worker (S-14, ADR-0015): acquire the parked /// BeoordelingEscaleren jobs — the tokens the 14-day boundary timer on Beoordelen spawns /// — reassign each instance's still-open Beoordelen task to the teamlead, and complete the job. /// A job that fails is logged and left un-completed so Flowable redelivers it (§8.6). Split out from /// the hosted pump so the acquire→reassign→complete logic is unit-testable without a running host. /// public sealed class BeoordelingEscalatieProcessor( IBeoordelingEscalatieClient client, ILogger logger) { /// Acquire and process up to escalations. Returns the number acquired. public async Task PumpOnceAsync(int maxJobs, CancellationToken ct = default) { var jobs = await client.AcquireBeoordelingEscalatieJobsAsync(maxJobs, ct); foreach (var job in jobs) { try { await client.ReassignBeoordelingToTeamleadAsync(job.ProcessInstanceId, ct); await client.CompleteBeoordelingEscalatieJobAsync(job.JobId, ct); } catch (Exception ex) { // Leave the job un-completed: its lock expires and Flowable redelivers it (§8.6). logger.LogError(ex, "BeoordelingEscaleren job {JobId} failed; leaving it for redelivery.", job.JobId); } } return jobs.Count; } }