Files
upstream-zulip/zerver/views/health.py
upstream-mirror 64898b2c79
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
2026-09-15 15:05:30 +05:00

68 lines
2.2 KiB
Python

from django.conf import settings
from django.db.migrations.recorder import MigrationRecorder
from django.http import HttpRequest, HttpResponse
from django.utils.crypto import get_random_string
from django.utils.translation import gettext as _
from pika import BlockingConnection
from zerver.lib.cache import cache_delete, cache_get, cache_set
from zerver.lib.exceptions import ServerNotReadyError
from zerver.lib.queue import get_queue_client
from zerver.lib.redis_utils import get_redis_client
from zerver.lib.response import json_success
def check_database() -> None:
try:
if not MigrationRecorder.Migration.objects.exists():
raise ServerNotReadyError(_("Database is empty")) # nocoverage
except ServerNotReadyError: # nocoverage
raise
except Exception: # nocoverage
raise ServerNotReadyError(_("Cannot query postgresql"))
def check_rabbitmq() -> None: # nocoverage
try:
conn = get_queue_client().connection
if conn is None:
raise ServerNotReadyError(_("Cannot connect to rabbitmq"))
assert isinstance(conn, BlockingConnection)
conn.process_data_events()
except ServerNotReadyError:
raise
except Exception:
raise ServerNotReadyError(_("Cannot query rabbitmq"))
def check_redis() -> None:
try:
get_redis_client().ping()
except Exception: # nocoverage
raise ServerNotReadyError(_("Cannot query redis"))
def check_memcached() -> None:
try:
roundtrip_key = "health_check_" + get_random_string(32)
roundtrip_value = get_random_string(32)
cache_set(roundtrip_key, roundtrip_value)
got_value = cache_get(roundtrip_key)[0]
if got_value != roundtrip_value:
raise ServerNotReadyError(_("Cannot write to memcached")) # nocoverage
cache_delete(roundtrip_key)
except ServerNotReadyError: # nocoverage
raise
except Exception: # nocoverage
raise ServerNotReadyError(_("Cannot query memcached"))
def health(request: HttpRequest) -> HttpResponse:
check_database()
if settings.USING_RABBITMQ: # nocoverage
check_rabbitmq()
check_redis()
check_memcached()
return json_success(request)