Skip to content

Add heartbeat listener for liveness probes - #60

Merged
DavidBadura merged 3 commits into
1.7.xfrom
heartbeat-listener
Oct 5, 2026
Merged

DavidBadura merged 3 commits into
1.7.xfrom
heartbeat-listener

Conversation

@DavidBadura

Copy link
Copy Markdown
Member

A process manager only sees whether the worker process is alive, not whether it hangs in a job. This adds a HeartbeatListener that touches a file when the worker starts and after every iteration, and removes it when the worker stops (which since #52 also happens when the job throws). A liveness probe can then restart the worker if the file gets too old. It can be enabled with the new heartbeatFile option in create(), and the docs include a Kubernetes probe example.

If the file can't be written, the listener logs a warning and the worker keeps running. The probe will notice it anyway, so there's no point in crashing the worker over it.

The file is only updated between iterations, so the probe threshold has to be larger than the longest job plus the sleep timer. The docs point that out.

This adds an option next to the one from #59, so whichever is merged second needs a small rebase.

HeartbeatListener touches a file when the worker starts and after every
iteration and removes it when the worker stops, so a liveness probe can
detect a worker that hangs in a job. It can be enabled with the new
heartbeatFile option in create().
@DavidBadura DavidBadura added this to the 1.7.0 milestone Oct 4, 2026
@DavidBadura DavidBadura added the enhancement New feature or request label Oct 4, 2026
The test measured the job with the real clock and expected 0ms, which
fails whenever the job run crosses a millisecond boundary.
@DavidBadura
DavidBadura merged commit 9fe8223 into 1.7.x Oct 5, 2026
16 checks passed
@DavidBadura
DavidBadura deleted the heartbeat-listener branch October 5, 2026 04:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants