From f272884587abec54263ac63c4a56f0a99760799a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 12 Nov 2024 13:47:25 +0100 Subject: [PATCH] chore: use constant to define heartbeat frequency --- weblate/utils/apps.py | 7 ++++++- weblate/utils/const.py | 1 + weblate/utils/tasks.py | 4 +++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/weblate/utils/apps.py b/weblate/utils/apps.py index 04f0e90d7a2f..d38af91b8b83 100644 --- a/weblate/utils/apps.py +++ b/weblate/utils/apps.py @@ -29,6 +29,7 @@ from .celery import is_celery_queue_long from .checks import weblate_check from .classloader import ClassLoader +from .const import HEARTBEAT_FREQUENCY from .data import data_dir from .db import ( MySQLSearchLookup, @@ -155,7 +156,11 @@ def check_celery( heartbeat = cache.get("celery_heartbeat") loaded = cache.get("celery_loaded") now = time.time() - if loaded and now - loaded > 120 and (not heartbeat or now - heartbeat > 600): + if ( + loaded + and now - loaded > HEARTBEAT_FREQUENCY + and (not heartbeat or now - heartbeat > HEARTBEAT_FREQUENCY * 10) + ): errors.append( weblate_check( "weblate.C030", diff --git a/weblate/utils/const.py b/weblate/utils/const.py index 9e8910aaf21e..e79b46ab4ae0 100644 --- a/weblate/utils/const.py +++ b/weblate/utils/const.py @@ -3,3 +3,4 @@ # SPDX-License-Identifier: GPL-3.0-or-later SUPPORT_STATUS_CACHE_KEY = "weblate:support:status" +HEARTBEAT_FREQUENCY = 120 diff --git a/weblate/utils/tasks.py b/weblate/utils/tasks.py index 753432e78034..5f6e6aeea13d 100644 --- a/weblate/utils/tasks.py +++ b/weblate/utils/tasks.py @@ -31,6 +31,8 @@ from weblate.utils.lock import WeblateLockTimeoutError from weblate.vcs.models import VCS_REGISTRY +from .const import HEARTBEAT_FREQUENCY + @app.task(trail=False) def ping(): @@ -178,4 +180,4 @@ def setup_periodic_tasks(sender, **kwargs) -> None: sender.add_periodic_task( crontab(hour=1, minute=30), database_backup.s(), name="database-backup" ) - sender.add_periodic_task(120, heartbeat.s(), name="heartbeat") + sender.add_periodic_task(HEARTBEAT_FREQUENCY, heartbeat.s(), name="heartbeat")