From 0f5f18bec727be14cc3e15fb6970d48502d84d03 Mon Sep 17 00:00:00 2001 From: lowercase00 <21188280+lowercase00@users.noreply.github.com> Date: Wed, 25 Jan 2023 08:57:15 -0300 Subject: [PATCH] Allow for configurable scheduler fallback period (#1759) * Allow for configurable scheduler fallback period This adds a parameter to the Scheduler called `fallback_period`, which determines the period before work fallsback to a new scheduler. * Update defaults.py Reduce Scheduler Fallback Period to 120 seconds. * Update scheduler.py Remove fallback period parameter. --- rq/defaults.py | 1 + rq/scheduler.py | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/rq/defaults.py b/rq/defaults.py index 93f603e8..2e99a289 100644 --- a/rq/defaults.py +++ b/rq/defaults.py @@ -8,5 +8,6 @@ DEFAULT_JOB_MONITORING_INTERVAL = 30 DEFAULT_RESULT_TTL = 500 DEFAULT_FAILURE_TTL = 31536000 # 1 year in seconds DEFAULT_LOGGING_DATE_FORMAT = '%H:%M:%S' +DEFAULT_SCHEDULER_FALLBACK_PERIOD = 120 DEFAULT_LOGGING_FORMAT = '%(asctime)s %(message)s' CALLBACK_TIMEOUT = 60 diff --git a/rq/scheduler.py b/rq/scheduler.py index 577976c0..4305cdea 100644 --- a/rq/scheduler.py +++ b/rq/scheduler.py @@ -9,7 +9,8 @@ from multiprocessing import Process from redis import SSLConnection, UnixDomainSocketConnection -from .defaults import DEFAULT_LOGGING_DATE_FORMAT, DEFAULT_LOGGING_FORMAT +from .defaults import (DEFAULT_LOGGING_DATE_FORMAT, DEFAULT_LOGGING_FORMAT, + DEFAULT_SCHEDULER_FALLBACK_PERIOD) from .job import Job from .logutils import setup_loghandlers from .queue import Queue @@ -98,7 +99,7 @@ class RQScheduler: return False if not self.lock_acquisition_time: return True - return (datetime.now() - self.lock_acquisition_time).total_seconds() > 600 + return (datetime.now() - self.lock_acquisition_time).total_seconds() > DEFAULT_SCHEDULER_FALLBACK_PERIOD def acquire_locks(self, auto_start=False): """Returns names of queue it successfully acquires lock on"""