Refactor scheduler lock implementation with heartbeat mechanism
- Add heartbeat-based lock renewal in scheduler_lock_heartbeat.py - Update scheduler_lock.py with improved lock management - Add comprehensive tests for scheduler lock functionality - Update deployment and task documentation Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -51,11 +51,16 @@ log: structlog.stdlib.BoundLogger = structlog.get_logger()
|
||||
|
||||
# Lock record expires if heartbeat hasn't been updated for this many seconds.
|
||||
# This prevents stale locks from a crashed instance from blocking new startups.
|
||||
# Set conservatively to allow temporary delays (e.g., high load) before considering
|
||||
# the lock abandoned.
|
||||
SCHEDULER_LOCK_TTL_SECONDS: int = 60
|
||||
|
||||
# Heartbeat interval: how often to update the lock's heartbeat_at timestamp.
|
||||
# Must be less than TTL to prevent premature expiration.
|
||||
SCHEDULER_LOCK_HEARTBEAT_INTERVAL_SECONDS: int = 10
|
||||
# Must be significantly less than TTL (at least 3-4x smaller) to allow multiple
|
||||
# consecutive missed heartbeats before the lock is considered stale.
|
||||
# With TTL=60s and interval=5s, the lock survives ~12 missed heartbeats before
|
||||
# expiring, providing robust protection against temporary delays.
|
||||
SCHEDULER_LOCK_HEARTBEAT_INTERVAL_SECONDS: int = 5
|
||||
|
||||
|
||||
async def init_scheduler_lock_table(db: aiosqlite.Connection) -> None:
|
||||
|
||||
Reference in New Issue
Block a user