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}}}
Set PY_HEALTH_TEST_MODE to disable the functionality. Your functions will run without any intervention and no port will be listened
Metadata
Release files for healthcheck-python 0.11.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| healthcheck-python-0.11.1.tar.gz | 14.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| healthcheck_python-0.11.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 34.8 kB
Release files / healthcheck-python-0.11.1.tar.gz
| Download URL | healthcheck-python-0.11.1.tar.gz |
|---|---|
| Size | 14.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
32b370536facf611b52d267364cad3b6b607c3188397ebc97cf49b8dcd8aef6e
|
|
BLAKE2b-256 checksum How to use checksums |
aa16ef48f350a9807babd0415699af8937a2c0aedb4ecaf2085695c3d7aaec51
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.1
|
Release files / healthcheck_python-0.11.1-py3-none-any.whl
| Download URL | healthcheck_python-0.11.1-py3-none-any.whl |
|---|---|
| Size | 19.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6aebbfa650855e5914bc4ab6af48375442f9a324c8df0242e8333de68afead0a
|
|
BLAKE2b-256 checksum How to use checksums |
78b207c30eebda720d5ebcd8cb0c530fbbc18abe88bfcb878266849bb1c70a99
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.1
|