Skip to main content

Tiny asynchronous implementation of healthcheck provider and http-server

Project description

aio_tiny_healthcheck

PyPI Build Status Build Status

Tiny asynchronous implementation of healthcheck provider and server

Usage

By default, the AioTinyHealthcheck returns 200 if all checks successfully finish or 500 in opposite case.

Using with aiohttp

from aiohttp import web

from aio_tiny_healthcheck.aio_tiny_healthcheck import AioTinyHealthcheck

def some_sync_check():
    return True

async def some_async_check():
    return False

healthcheck_provider = AioTinyHealthcheck()
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.aio_tiny_healthcheck import AioTinyHealthcheck

app = Sanic()

def some_sync_check():
    return True

async def some_async_check():
    return False

healthcheck_provider = AioTinyHealthcheck(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.aio_tiny_healthcheck import AioTinyHealthcheck
from aio_tiny_healthcheck.healthcheck_server_http import HealthcheckServerHttp
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 = AioTinyHealthcheck()
hc_server = HealthcheckServerHttp(
    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)


async def main():
    asyncio.create_task(hc_server.run())
    await some_long_task()


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())

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

aio_tiny_healthcheck-0.1.3.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aio_tiny_healthcheck-0.1.3-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file aio_tiny_healthcheck-0.1.3.tar.gz.

File metadata

  • Download URL: aio_tiny_healthcheck-0.1.3.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8

File hashes

Hashes for aio_tiny_healthcheck-0.1.3.tar.gz
Algorithm Hash digest
SHA256 d3da997fc97b71cb06d8c09a5da26c08c6cc81e771fdf84f8511638e4200557c
MD5 e7e47f2301b2d6aac8c5c2478b9493a5
BLAKE2b-256 1934c909b95afab95663edc9e6337f4786ecf83fb0bbb1ffc547eb14968a7cc8

See more details on using hashes here.

File details

Details for the file aio_tiny_healthcheck-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: aio_tiny_healthcheck-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8

File hashes

Hashes for aio_tiny_healthcheck-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d87389e84c8dbcb15eee889e52f3f8c0fa62e75ba78b8e670ac029a362b7ed80
MD5 ea3fe332d7391bc708e03e9dfdb93794
BLAKE2b-256 9cda581a5cf754fe3096d19d8602397d05f300323dcc1a0ba9859b98315776e3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page