-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add endpoint which returns 500 if any critical errors in sendpo…
…st.py occur (#390) * chore: allow print calls to show in docker log * feat: set up health check endpoint * fix: correct import
- Loading branch information
1 parent
9e3d41c
commit de02a02
Showing
6 changed files
with
70 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from typing import Optional, Tuple, List | ||
|
||
''' | ||
Utils class to check app health. | ||
Used for Kubernetes to automatically restart app when critical errors occur. | ||
Process: | ||
1. A critical error occurs | ||
2. HealthCheck receives notification of this via setUnhealthy(msg: Optional[str]) method | ||
3. HealthCheck keeps changes program state to unhealthy, and keeps track of the message | ||
4. A routine call to the healthcheck API occurs | ||
a. API calls healthCheck() which returns current status | ||
b. If program not in healthy state, API returns 500 status code along with messages | ||
c. If program is healthy, API returns 200 OK | ||
''' | ||
class HealthCheck(object): | ||
# Static var | ||
_healthy = True | ||
_message: List[str] = [] | ||
|
||
# Used to set global healthiness, with optional message | ||
@staticmethod | ||
def setUnhealthy(message: Optional[str] = None) -> None: | ||
HealthCheck._healthy = False | ||
|
||
if message: | ||
HealthCheck._message.append(message) | ||
|
||
# Returns global healthiness | ||
@staticmethod | ||
def healthCheck() -> Tuple[bool, str]: | ||
return (HealthCheck._healthy, HealthCheck._message) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.