-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathviews.py
More file actions
55 lines (39 loc) · 1.29 KB
/
views.py
File metadata and controls
55 lines (39 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import logging
import os
from fastapi import Request, Response
from dockerflow import checks
from ..version import get_version
logger = logging.getLogger(__name__)
def lbheartbeat():
return {"status": "ok"}
async def heartbeat(request: Request, response: Response):
FAILED_STATUS_CODE = int(
getattr(request.app.state, "DOCKERFLOW_HEARTBEAT_FAILED_STATUS_CODE", "500")
)
check_results = await checks.run_checks_async(
checks.get_checks().items(),
)
payload = {
"status": checks.level_to_text(check_results.level),
"checks": check_results.statuses,
"details": check_results.details,
}
if check_results.level < checks.ERROR:
response.status_code = 200
else:
response.status_code = FAILED_STATUS_CODE
return payload
def version(request: Request):
if getattr(request.app.state, "APP_DIR", None):
root = request.app.state.APP_DIR
elif os.getenv("APP_DIR"):
root = os.getenv("APP_DIR")
else:
root = "/app"
return get_version(root)
def error(request: Request):
"""
A view that raises an exception, used to test error handling.
"""
logger.error("The __error__ endpoint was called")
raise Exception("This is a test exception from the /__error__ endpoint.")