| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Ecluse.Core.Worker.Loop
Description
Loop robustness and supervision for the worker.
The loop is wrapped so a single bad iteration cannot kill the worker thread: a
transient receive fetch publish error, or an undecodable body, is caught,
logged, and the loop backs off and continues. (Job-level "retry is don't ack" is a
separate concern -- it governs whether one message redelivers; it does not protect
the loop, since an escaping exception would still tear the thread down.) The
composition root holds the worker under concurrently_ alongside the server, so a
genuinely fatal error propagates and takes the process down (fail-stop), while
transient faults self-recover here. A successful poll advances the WorkerHeartbeat,
so a stalled loop is visible to the liveness probe.
Shutdown tears the loop down cleanly: the composition root runs it under
concurrently_ within its resource bracket, so process teardown cancels the loop
thread and an in-flight, un-acked message simply redelivers -- safe, because
publishing is idempotent (a version already present is success).
Synopsis
- workerLoop :: WorkerM ()
Documentation
workerLoop :: WorkerM () Source #
The continuous consume loop: long-poll for a batch, process it, repeat.
Each iteration is wrapped so a single failure -- a receive that throws, a fetch or
publish error, an undecodable body -- is caught and logged, then the loop backs off
briefly and continues, so one bad iteration cannot kill the worker thread. A
successful poll advances the heartbeat (whether or not the batch was empty), so a
liveness probe sees the loop is alive; an idle queue is a healthy empty poll, not a
stall.