fix: Prevent multiple schedulers from running on same bench (#25340)

This commit is contained in:
Ankush Menat 2024-03-11 19:42:31 +05:30 committed by GitHub
parent c441c844f9
commit 8bbb69a883
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 5 deletions

View file

@ -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:

View file

@ -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)