Skip to content

Commit 3b0d04e

Browse files
authored
Deprecate APIs to prepare for v4's async checks (#589)
1 parent 12f0236 commit 3b0d04e

File tree

3 files changed

+17
-63
lines changed

3 files changed

+17
-63
lines changed

docs/install.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,11 @@ urlpatterns = [
5555
{"client": Redis.from_url("redis://localhost:6379")},
5656
),
5757
],
58-
use_threading=True, # optional, default is True
59-
warnings_as_errors=True, # optional, default is True
6058
),
6159
),
6260
]
6361
```
6462

65-
## Threading
66-
67-
Django Health Check runs each check in a separate thread by default to improve performance. If you prefer to run the checks sequentially, you can set the `use_threading` parameter to `False` when instantiating the `HealthCheckView`, as shown in the example above.
68-
69-
This can be useful in environments where threads are not closing IO connections properly, leading to resource leaks.
70-
However, for Django's database connections, threading is generally safe and recommended for better performance.
71-
72-
## Warnings as Errors
73-
74-
Treats `ServiceWarning` as errors, meaning they will cause the views to respond with a 500 status code. Default is `True`.
75-
If set to `False` warnings will be displayed in the template or in the JSON response but the status code will remain a 200.
76-
7763
## Security
7864

7965
You can protect the health check endpoint by adding a secure token to your URL.

docs/usage.md

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -70,54 +70,6 @@ class MyHealthCheckBackend(HealthCheck):
7070

7171
::: health_check.HealthCheck
7272

73-
## Customizing output
74-
75-
You can customize HTML or JSON rendering by inheriting from [HealthCheckView][health_check.views.HealthCheckView]
76-
and customizing the `template_name`, `get`,
77-
`render_to_response` and `render_to_response_json` properties:
78-
79-
```python
80-
# views.py
81-
from django.http import HttpResponse, JsonResponse
82-
83-
from health_check.views import HealthCheckView
84-
85-
86-
class HealthCheckCustomView(HealthCheckView):
87-
template_name = "myapp/health_check_dashboard.html" # customize the used templates
88-
89-
def get(self, request, *args, **kwargs):
90-
plugins = []
91-
status = 200 # needs to be filled status you need
92-
#
93-
if "application/json" in request.META.get("HTTP_ACCEPT", ""):
94-
return self.render_to_response_json(plugins, status)
95-
return self.render_to_response(plugins, status)
96-
97-
def render_to_response(self, plugins, status): # customize HTML output
98-
return HttpResponse("COOL" if status == 200 else "SWEATY", status=status)
99-
100-
def render_to_response_json(self, plugins, status): # customize JSON output
101-
return JsonResponse({repr(p): "COOL" if status == 200 else "SWEATY" for p in plugins}, status=status)
102-
103-
104-
# urls.py
105-
from django.urls import path
106-
107-
from . import views
108-
109-
urlpatterns = [
110-
#
111-
path(
112-
"ht/",
113-
views.HealthCheckCustomView.as_view(checks=["myapp.health_checks.MyHealthCheckBackend"]),
114-
name="health_check_custom",
115-
),
116-
]
117-
```
118-
119-
::: health_check.views.HealthCheckView
120-
12173
## Django command
12274

12375
You can run the Django command `health_check` to perform your health
@@ -134,5 +86,5 @@ Database ... OK
13486
CustomHealthCheck ... unavailable: Something went wrong!
13587
```
13688

137-
Similar to the http version, a critical error will cause the command to
89+
Similar to the http version, an error will cause the command to
13890
quit with the exit code `1`.

health_check/views.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
import warnings
23
from functools import cached_property
34

45
from django.db import transaction
@@ -146,6 +147,21 @@ class HealthCheckView(_MainView):
146147

147148
checks: list[str | tuple[str, dict]] | None = None
148149

150+
def as_view(self, **initkwargs):
151+
if "warnings_as_errors" in initkwargs:
152+
warnings.warn(
153+
"`warnings_as_errors` argument is deprecated and will be removed the next major version.",
154+
DeprecationWarning,
155+
stacklevel=2,
156+
)
157+
if "use_threading" in initkwargs:
158+
warnings.warn(
159+
"`use_threading` argument is deprecated and will be removed the next major version.",
160+
DeprecationWarning,
161+
stacklevel=2,
162+
)
163+
super().as_view(**initkwargs)
164+
149165
def get_plugins(self):
150166
for check in self.checks or [
151167
"health_check.Cache",

0 commit comments

Comments
 (0)