Implement BeoordelingEscalatieProcessor.PumpOnceAsync over the escalation client. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
38 lines
1.6 KiB
C#
38 lines
1.6 KiB
C#
using Microsoft.Extensions.Logging;
|
|
|
|
namespace Big.Infrastructure;
|
|
|
|
/// <summary>
|
|
/// One poll tick of the beoordeling-escalation worker (S-14, ADR-0015): acquire the parked
|
|
/// <c>BeoordelingEscaleren</c> jobs — the tokens the 14-day boundary timer on <c>Beoordelen</c> spawns
|
|
/// — reassign each instance's still-open <c>Beoordelen</c> 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.
|
|
/// </summary>
|
|
public sealed class BeoordelingEscalatieProcessor(
|
|
IBeoordelingEscalatieClient client,
|
|
ILogger<BeoordelingEscalatieProcessor> logger)
|
|
{
|
|
/// <summary>Acquire and process up to <paramref name="maxJobs"/> escalations. Returns the number acquired.</summary>
|
|
public async Task<int> 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;
|
|
}
|
|
}
|