diff --git a/frappe/utils/scheduler.py b/frappe/utils/scheduler.py index 6f9ce6b010..03368f956f 100644 --- a/frappe/utils/scheduler.py +++ b/frappe/utils/scheduler.py @@ -20,6 +20,7 @@ import setproctitle import frappe from frappe.utils import cint, get_datetime, get_sites, now_datetime from frappe.utils.background_jobs import set_niceness +from frappe.utils.synchronization import filelock DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S" @@ -44,10 +45,11 @@ def start_scheduler() -> NoReturn: tick = cint(frappe.get_conf().scheduler_tick_interval) or 60 set_niceness() - while True: - _proctitle("idle") - time.sleep(tick) - enqueue_events_for_all_sites() + with filelock("scheduler_process", timeout=1, is_global=True): + while True: + _proctitle("idle") + time.sleep(tick) + enqueue_events_for_all_sites() def enqueue_events_for_all_sites() -> None: diff --git a/frappe/utils/synchronization.py b/frappe/utils/synchronization.py index 0f7aeb1527..f86b401d59 100644 --- a/frappe/utils/synchronization.py +++ b/frappe/utils/synchronization.py @@ -40,7 +40,7 @@ def filelock(lock_name: str, *, timeout=30, is_global=False): with _StrongFileLock(lock_path, timeout=timeout): yield except Timeout as e: - frappe.log_error("Filelock: Failed to aquire {lock_path}") + frappe.log_error(f"Filelock: Failed to aquire {lock_path}") raise LockTimeoutError( _("Failed to aquire lock: {}. Lock may be held by another process.").format(lock_name)