PK!-sanic_healthchecks/__init__.py"""Top level package definition for sanic_healthchecks Includes import for running a healthcheck server on a different thread """ from sanic_healthchecks.core import start_healthcheck_server __all__ = ["start_healthcheck_server"] PK!sanic_healthchecks/core.py"""The core of running a healthcheck server on a different thread. It's useful to run the healthchecks on a different web server entirely, because it means that we're not going to take away any resources from the thread that is running the actual Sanic application itself. The healthchecks should report that the downstream and required dependencies of a service are still accessible from the host or container that is running the actual Sanic application. """ import asyncio import threading from aiohttp import web async def main(handler, host, port): """The main entrypoint for running an aiohttp server. This function will start an async compatible aiohttp server. There's no other fancy logic or configuration. The handler that is passed in will be available as an endpoint at the root path of whatever port gets specified. Requests will be made by sending an HTTP GET verb to: http://{host}:{port}/ """ server = web.Server(handler) runner = web.ServerRunner(server) await runner.setup() site = web.TCPSite(runner, host, port) await site.start() print(f"======= Listening for healthchecks on http://{host}:{port}/ ======") # pause here for very long time by serving HTTP requests and # waiting for keyboard interruption while True: await asyncio.sleep(100 * 3600) def start_healthcheck_server(handler, host="0.0.0.0", port=8082): """Start the actual web server to respond to healthcheck requests. We need to make sure that this web server is non-blocking, so that the Sanic application can be instantiated as expected. """ loop = asyncio.get_event_loop() httpd = threading.Thread( target=lambda: loop.run_until_complete(main(handler, host, port)) ) httpd.daemon = True httpd.start() PK!HڽTU(sanic_healthchecks-0.1.0.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!H ;+sanic_healthchecks-0.1.0.dist-info/METADATAQKO@ﯘ&hL5"$@!zCpw ;+:zۙ{)`r^E9*ER6.j*^|zi?U.!xM{֒qp+u2 _γδVQFQbb;4_b& ҞZLW[1lCmBۇ*!91UlQZ'ˎv^\rQˍ$fc60HdY>ZpΟ-^ !>PK!Hh)sanic_healthchecks-0.1.0.dist-info/RECORDr0@ѽDŽEbLj`&A Uƙδ ܹ:WQLpvJ ƹZ6tnHj4ezbm) 'a/';m[";3KÀu87,ς}Ӱ IWdq \3M.IbE\UxԘ+2[~G+Yp4i"AR^Ps1<h9$xDczPK!-sanic_healthchecks/__init__.pyPK!$sanic_healthchecks/core.pyPK!HڽTU(ssanic_healthchecks-0.1.0.dist-info/WHEELPK!H ;+ sanic_healthchecks-0.1.0.dist-info/METADATAPK!Hh) sanic_healthchecks-0.1.0.dist-info/RECORDPK