[neat_periodic_task] Add heartbeat locks to NeatPeriodicTaskScheduler - #408
Open
sigurdm wants to merge 3 commits into
Open
[neat_periodic_task] Add heartbeat locks to NeatPeriodicTaskScheduler#408sigurdm wants to merge 3 commits into
sigurdm wants to merge 3 commits into
Conversation
Enhance NeatPeriodicTaskScheduler to periodically refresh a heartbeat timestamp in the status file while running. If an instance crashes, encounters an OOM, or is killed abruptly while running a periodic task, other schedulers can detect the stale heartbeat after `heartbeatTimeout` and reclaim the task without having to wait for the full (often long, e.g. 12-hour) task `timeout`.
sigurdm
force-pushed
the
heartbeat-locks
branch
from
August 28, 2026 08:51
a9e7ce3 to
d286313
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds heartbeat support to
NeatPeriodicTaskSchedulerinpackage:neat_periodic_task.Motivation
Currently, when a periodic task is claimed by a worker instance, the status file is set to
state: 'running'withstarted: now. If that worker is terminated abruptly (e.g. SIGKILL, container replacement, App Engine / GCE VM shutdown, OOM):state: 'running'.state: 'running'and assume the task is still executing. They will back off and not retry until_timeouthas elapsed.Changes
NeatTaskStatus:DateTime? heartbeatproperty.NeatPeriodicTaskScheduler:heartbeatIntervalandheartbeatTimeoutconstructor parameters.heartbeatIntervalis provided,heartbeatTimeoutdefaults to3 * heartbeatInterval. If onlyheartbeatTimeoutis provided,heartbeatIntervaldefaults toheartbeatTimeout ~/ 3._task()is executing, a periodic timer updates theheartbeattimestamp in_statusProvider._iteration(), ifstatus.state == 'running', other schedulers check whether the heartbeat has expired (now.difference(status.heartbeat) >= _heartbeatTimeout). If expired, the worker is presumed dead and the task is reclaimed immediately without waiting for the full_timeout.trigger()also reclaims the task if the heartbeat is expired._timeout, and trigger reclamation.