Tiny asynchronous implementation of healthcheck provider and http-server
Project description
aio_tiny_healthcheck
Tiny asynchronous implementation of healthcheck provider and server
Usage
By default, the Checker returns 200 if all checks successfully finish or 500 in opposite case.
Using with aiohttp
from aiohttp import web
from aio_tiny_healthcheck.checker import Checker
def some_sync_check():
return True
async def some_async_check():
return False
healthcheck_provider = Checker()
healthcheck_provider.add_check('sync_check_true', some_async_check)
healthcheck_provider.add_check('async_check_false', some_async_check)
app = web.Application()
app.router.add_get('/healthcheck', healthcheck_provider.aiohttp_handler)
web.run_app(app)
Using with Sanic
from sanic import Sanic
from sanic.response import json
from aio_tiny_healthcheck.checker import Checker
app = Sanic()
def some_sync_check():
return True
async def some_async_check():
return False
healthcheck_provider = Checker(success_code=201, fail_code=400)
healthcheck_provider.add_check('sync_check_true', some_async_check)
healthcheck_provider.add_check('async_check_false', some_async_check)
@app.route("/healthcheck")
async def test(request):
hc_response = healthcheck_provider.check_handler()
return json(hc_response.body, status=hc_response.code)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000)
Using in concurrent mode
You should want to run healthcheck in background if you already have some blocking operation in your wxwcution flow. So, you can just use built-in server for this.
from aio_tiny_healthcheck.checker import Checker
from aio_tiny_healthcheck.http_server import HttpServer
import asyncio
async def some_long_task():
await asyncio.sleep(3600)
def some_sync_check():
return True
async def some_async_check():
return True
aio_thc = Checker()
hc_server = HttpServer(
aio_thc,
path='/health',
host='localhost',
port=9090
)
aio_thc.add_check('sync_check_true', some_async_check)
aio_thc.add_check('async_check_false', some_async_check)
Project details
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
Close
Hashes for aio_tiny_healthcheck-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87c217514a95de9d797cb25d58b1d7fe2776b1ae4403a6732b60f81d604aeb57 |
|
MD5 | ec8df52e5a1e017ada51b371b00918dd |
|
BLAKE2b-256 | 7366ef0b978ba722b26994d112137dd8a54c08af26acdcb125584871d0524cbc |
Close
Hashes for aio_tiny_healthcheck-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a6c2805913a037c1b2da9c06626e2962a6e7bb0f06ab570b90d94f4b4fadb4c |
|
MD5 | e7c41d0cb517046794ff624ca21a4ee8 |
|
BLAKE2b-256 | 8f58c30f44b8ff4e6848cd55222f3e9506c49802adfb50b01d17f57c753d240d |