django-health-check 3.21.1__py3-none-any.whl → 3.22.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: django-health-check
3
- Version: 3.21.1
3
+ Version: 3.22.0
4
4
  Summary: Monitor the health of your Django app and its connected services.
5
5
  Keywords: django,postgresql
6
6
  Author-email: Kristian Ollegaard <kristian@oellegaard.com>, Johannes Maron <johannes@maron.family>
@@ -1,5 +1,5 @@
1
1
  health_check/__init__.py,sha256=vLH1k9cjhuLe_swu-qMxrz1_7fFJA179-UWNcsdA8QA,868
2
- health_check/_version.py,sha256=lnu-yfgOzv6DG7Vjh0cOUPFmVZ0swqx_iu6PWn47660,714
2
+ health_check/_version.py,sha256=fYOTYhtJ3EebEFBMa41v24xwRC5E0azzRRvSxT74Jtg,714
3
3
  health_check/backends.py,sha256=Q4B8yRusBZz8mOz8jNZmqJWQ1Fu6YawYiLNFkw5sUmA,3414
4
4
  health_check/conf.py,sha256=l3Utl8zLLT42TKUnBFNLnD_i-wYNKmxPXVVyIucGUXc,319
5
5
  health_check/deprecation.py,sha256=uYGwPFW8lX1xQ33x0VRkoPFoyoLcrMt6DmpX3RHLxj4,1127
@@ -36,7 +36,7 @@ health_check/contrib/rabbitmq/apps.py,sha256=i-1Uo3W6Ofc0_StFABfrxysh_anWVP-mcNK
36
36
  health_check/contrib/rabbitmq/backends.py,sha256=22zNDsX-Ie-a5Rwk4naIpGB3184SV2OaGTXzwBzWbU0,1836
37
37
  health_check/contrib/redis/__init__.py,sha256=TzSbuXNst7itI8mbrtsCNJXJP40ZpX-r2x6mxMNTgYE,69
38
38
  health_check/contrib/redis/apps.py,sha256=1bhVAy5iKZer8IwG4WXZYeYUSl7AMTtNPRRhR5ugrLs,700
39
- health_check/contrib/redis/backends.py,sha256=UuKWmSD4CzM48f6Ora-IuqoqV8jeX3u9UVZG4-ckrgg,1896
39
+ health_check/contrib/redis/backends.py,sha256=xQ73bnGlOGtvnaNiEOz4bhqxXsD-Qn2y6aVwoiQkWCg,2788
40
40
  health_check/contrib/s3boto3_storage/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
41
41
  health_check/contrib/s3boto3_storage/apps.py,sha256=1-7X_v7d6HeKD5MBxyDvrh5vdopsvmnJNjToiFjeDx4,732
42
42
  health_check/contrib/s3boto3_storage/backends.py,sha256=0WrNNNJiqDVn5_GHQZm6hlEBvSxhWTqWSWUtmVHkzzo,1331
@@ -57,7 +57,7 @@ health_check/storage/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hS
57
57
  health_check/storage/apps.py,sha256=f6958Deq62DXoe8myL57rnKSkKkPQf2FLM9iJkUdx-U,293
58
58
  health_check/storage/backends.py,sha256=pkj64HcVnvm9pvgWFhL81IDejTOH8-pLSFwJQ_90jbs,2636
59
59
  health_check/templates/health_check/index.html,sha256=pOC7GW_r0gDQ5Qz5aJacNFI22N52kbiOzh4aZb9_V-Q,4045
60
- django_health_check-3.21.1.dist-info/licenses/LICENSE,sha256=19Rs8FInCokFQuq03cab_KHwpeyF5pt-lTp7pfJX1iE,1101
61
- django_health_check-3.21.1.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
62
- django_health_check-3.21.1.dist-info/METADATA,sha256=SH__WORk7gW7EFGzHjS-6rLuUMMIqVUhqiS8Vs53ibk,3554
63
- django_health_check-3.21.1.dist-info/RECORD,,
60
+ django_health_check-3.22.0.dist-info/licenses/LICENSE,sha256=19Rs8FInCokFQuq03cab_KHwpeyF5pt-lTp7pfJX1iE,1101
61
+ django_health_check-3.22.0.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
62
+ django_health_check-3.22.0.dist-info/METADATA,sha256=blyMILwBcnvuFzsfU8l_4HfDiQzuNRpZMr23vS4Y3Ig,3554
63
+ django_health_check-3.22.0.dist-info/RECORD,,
health_check/_version.py CHANGED
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
28
28
  commit_id: COMMIT_ID
29
29
  __commit_id__: COMMIT_ID
30
30
 
31
- __version__ = version = '3.21.1'
32
- __version_tuple__ = version_tuple = (3, 21, 1)
31
+ __version__ = version = '3.22.0'
32
+ __version_tuple__ = version_tuple = (3, 22, 0)
33
33
 
34
- __commit_id__ = commit_id = 'g8948ab942'
34
+ __commit_id__ = commit_id = 'g12f02362c'
@@ -1,9 +1,11 @@
1
1
  import dataclasses
2
2
  import logging
3
3
  import typing
4
+ import warnings
4
5
 
5
6
  from django.conf import settings
6
- from redis import exceptions, from_url
7
+ from redis import Redis as RedisClient
8
+ from redis import RedisCluster, exceptions
7
9
 
8
10
  from health_check.backends import HealthCheck
9
11
  from health_check.exceptions import ServiceUnavailable
@@ -14,37 +16,60 @@ logger = logging.getLogger(__name__)
14
16
  @dataclasses.dataclass
15
17
  class RedisHealthCheck(HealthCheck):
16
18
  """
17
- Check Redis service by pinging the redis instance with a redis connection.
19
+ Check Redis service by pinging a Redis client.
20
+
21
+ This check works with any Redis client that implements the ping() method,
22
+ including standard Redis, Sentinel, and Cluster clients.
18
23
 
19
24
  Args:
20
- redis_url: The Redis connection URL.
21
- redis_url_options: Additional options for the Redis connection.
25
+ client: A Redis client instance (Redis, Sentinel master, or Cluster).
26
+ If provided, this takes precedence over redis_url.
27
+
28
+ Examples:
29
+ Using a standard Redis client:
30
+ >>> from redis import Redis as RedisClient
31
+ >>> Redis(client=RedisClient(host='localhost', port=6379))
32
+
33
+ Using a Cluster client:
34
+ >>> from redis.cluster import RedisCluster
35
+ >>> Redis(client=RedisCluster(host='localhost', port=7000))
36
+
37
+ Using a Sentinel client:
38
+ >>> from redis.sentinel import Sentinel
39
+ >>> sentinel = Sentinel([('localhost', 26379)])
40
+ >>> Redis(client=sentinel.master_for('mymaster'))
22
41
 
23
42
  """
24
43
 
44
+ client: RedisClient | RedisCluster = dataclasses.field(default=None, repr=False)
25
45
  redis_url: str = dataclasses.field(default=getattr(settings, "REDIS_URL", "redis://localhost/1"), repr=False)
26
46
  redis_url_options: dict[str, typing.Any] = dataclasses.field(
27
- default=getattr(settings, "HEALTHCHECK_REDIS_URL_OPTIONS", None), repr=False
47
+ default_factory=lambda: getattr(settings, "HEALTHCHECK_REDIS_URL_OPTIONS", {}), repr=False
28
48
  )
29
49
 
30
- def check_status(self):
31
- logger.debug("Got %s as the redis_url. Connecting to redis...", self.redis_url)
50
+ def __post_init__(self):
51
+ if not self.client:
52
+ print(self.client)
53
+ warnings.warn(
54
+ "The 'redis_url' parameter is deprecated. Please use the 'client' parameter instead.",
55
+ DeprecationWarning,
56
+ stacklevel=2,
57
+ )
58
+ self.client = RedisClient.from_url(self.redis_url, **self.redis_url_options)
32
59
 
33
- logger.debug("Attempting to connect to redis...")
60
+ def check_status(self):
61
+ logger.debug("Pinging Redis client...")
34
62
  try:
35
- # conn is used as a context to release opened resources later
36
- with from_url(self.redis_url, **(self.redis_url_options or {})) as conn:
37
- conn.ping() # exceptions may be raised upon ping
63
+ self.client.ping()
38
64
  except ConnectionRefusedError as e:
39
- self.add_error(
40
- ServiceUnavailable("Unable to connect to Redis: Connection was refused."),
41
- e,
42
- )
65
+ raise ServiceUnavailable("Unable to connect to Redis: Connection was refused.") from e
43
66
  except exceptions.TimeoutError as e:
44
- self.add_error(ServiceUnavailable("Unable to connect to Redis: Timeout."), e)
67
+ raise ServiceUnavailable("Unable to connect to Redis: Timeout.") from e
45
68
  except exceptions.ConnectionError as e:
46
- self.add_error(ServiceUnavailable("Unable to connect to Redis: Connection Error"), e)
69
+ raise ServiceUnavailable("Unable to connect to Redis: Connection Error") from e
47
70
  except BaseException as e:
48
- self.add_error(ServiceUnavailable("Unknown error"), e)
71
+ raise ServiceUnavailable("Unknown error.") from e
49
72
  else:
50
73
  logger.debug("Connection established. Redis is healthy.")
74
+ finally:
75
+ self.client.close()