From 327d5e5b3c0a6782452ab9b3f338530133d572d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Dlouh=C3=BD?= Date: Sun, 20 Nov 2022 11:48:50 +0100 Subject: [PATCH] allow to execute one test multiple times with different parameters --- README.md | 23 ++++++++++++++--------- django_alive/utils.py | 13 ++++++++++++- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index a451ace..3f66a5f 100644 --- a/README.md +++ b/README.md @@ -60,20 +60,25 @@ If you wish to use the `healthcheck` [management command](#management-command), The default "health" endpoint will test a simple `SELECT 1` query on the database. Additional checks can be enabled in your Django settings. -Use the `ALIVE_CHECKS` setting to configure the checks to include. It is a dictionary with the path to a Python function as a key and any keyword arguments to pass to that function as a value. A full example: +Use the `ALIVE_CHECKS` setting to configure the checks to include. It is a list of tuples with the path to a Python function as a first argiment and dict of keyword arguments to pass to that function as a second argument. A full example: ```python -ALIVE_CHECKS = { - "django_alive.checks.check_database": {}, - "django_alive.checks.check_staticfile": { +ALIVE_CHECKS = [ + ("django_alive.checks.check_database", {}), + ("django_alive.checks.check_staticfile", { "filename": "img/favicon.ico", - }, - "django_alive.checks.check_cache": { + }), + ("django_alive.checks.check_cache", { "cache": "session", "key": "test123", - }, - "django_alive.checks.check_migrations": {}, -} + }), + ("django_alive.checks.check_migrations", {}), +] +``` + +**⚠️ Warning: DCanged in version 1.3.0 ⚠️⚠️** + +**NOTE:** Old settings with `ALIVE_CHECKS` as dict was deprecated in favor of a list of tuples. ``` diff --git a/django_alive/utils.py b/django_alive/utils.py index 1e8ce97..a838b55 100644 --- a/django_alive/utils.py +++ b/django_alive/utils.py @@ -1,3 +1,4 @@ +import warnings from django.conf import settings from django.utils.module_loading import import_string @@ -17,7 +18,17 @@ def perform_healthchecks(): # typing: () -> (bool, List[str]) errors = [] - for func, kwargs in ALIVE_CHECKS.items(): + if isinstance(ALIVE_CHECKS, dict): + # Deprecated dict format + warnings.warn( + "ALIVE_CHECKS should be a list of tuples, not a dict. " + "Please update your settings.", + DeprecationWarning, + ) + checks = ALIVE_CHECKS.items() + else: + checks = ALIVE_CHECKS + for func, kwargs in checks: try: import_string(func)(**kwargs) except HealthcheckFailure as e: