Skip to content

Commit

Permalink
chore: use constant to define heartbeat frequency
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Nov 12, 2024
1 parent a685a02 commit f272884
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
7 changes: 6 additions & 1 deletion weblate/utils/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions weblate/utils/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
# SPDX-License-Identifier: GPL-3.0-or-later

SUPPORT_STATUS_CACHE_KEY = "weblate:support:status"
HEARTBEAT_FREQUENCY = 120
4 changes: 3 additions & 1 deletion weblate/utils/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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")

0 comments on commit f272884

Please sign in to comment.