Health Check API for multiprocessing python apps
Project description
A Health Check API Library for Multiprocessing Python Apps
This library adds a health check REST API to your multiprocessing apps. You can add decorators to your periodic running
functions and library will track the function calls. This library supports multiprocessing threads. You can fetch
a single overall app status by fetching
http://<ip>:<port>/health, a single overall app readiness by fetching
http://<ip>:<port>/ready, or detailed statuses of all service with fetching
http://<ip>:<port>/health?v
http://<ip>:<port>/ready?v
Usage
Set PY_HEALTH_CHECK_HOST and PY_HEALTH_CHECK_PORT environment variable and add the appropriate decorator to
your periodic functions or class methods
import time
import multiprocessing as mp
import healthcheck_python
def run_continuously():
while True:
run_once()
time.sleep(1)
@healthcheck_python.periodic(service="my_service1", timeout=10)
@healthcheck_python.healthy(service="my_service1")
def run_once():
do_something()
@healthcheck_python.periodic(timeout=5)
class MyProcess(mp.Process):
def __init__(self, queue):
super().__init__()
self.queue = queue
self.continue_running = True
self.var = 0
def run(self):
self.init()
while self.continue_running:
self.do_the_thing_once()
time.sleep(1)
@healthcheck_python.healthy
def do_the_thing_once(self):
self.do_something()
@healthcheck_python.mark_ready
def init(self):
self.var = 1
@healthcheck_python.mark_done
def cleanup(self):
self.queue.close()
With these wrappers, run_once() has to called every 10 seconds and MyProcess.do_the_thing_once()
has to be called every 5 seconds. If at least one fails, the app status will be down.
$ curl http://localhost:8080/health
{"status": true}
$ curl http://localhost:8080/health?v
{"status": true, "ready": false, "services": {"my_service1": {"ready", false, "latest_start": 1611137135.3203568, "latest_end": 1611137135.3203998, "fps":0, "timeout": 10},"MyProcess": {"ready":true, "latest_start": 1611137135.3203568, "latest_end": 1611137135.3203998, "fps":0, "timeout": 5}}}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file healthcheck-python-0.8.0.tar.gz.
File metadata
- Download URL: healthcheck-python-0.8.0.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a56a5a89c44c7a66b6cb87a282904ade2aa06ef7b335cae5663f4f3f8f930320
|
|
| MD5 |
37bf8da254a86b4436a40443b57751c0
|
|
| BLAKE2b-256 |
a92cd9de073e9824417b8b06ab996fa0c340b9700acdd330e3be0c7d60545758
|
File details
Details for the file healthcheck_python-0.8.0-py3-none-any.whl.
File metadata
- Download URL: healthcheck_python-0.8.0-py3-none-any.whl
- Upload date:
- Size: 19.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
728b8b0f451776ad935fcf6798263af5f5462b5b6dcc806841256f67b7db3571
|
|
| MD5 |
2b7cc86447993fc0dea995660060c126
|
|
| BLAKE2b-256 |
56c90f0dfb924066feaf4b7477fe9cd9375da089d49b1939c8cb0f1c4ddc44cb
|