Simple application status handler for Tornado.
This library includes a very simple tornado.web.RequestHandler
that
returns an applications status information. You should install the
handler under the /status
path for a very simple healthcheck that
verifies the operation of the IOLoop (at the very least). This library
is the successor to the sprockets.handlers.status library. We have
moved away from a deeply nested package structure based on namespace
packages because they are actually more trouble than they are worth.
The simplest example is a JSON payload that contains directly configured
information. The application name and version is passed through the
URLSpec
keyword arguments to the status handler.
from tornado import ioloop, web
import sprockets_status.handlers
def make_app(**settings):
return web.Application([
web.url('/status', sprockets_status.handlers.StatusHandler,
{'name': 'my-app-name', 'version': '1.1.1'}),
# add your handlers here
], **settings)
if __name__ == '__main__':
app = make_app()
iol = ioloop.IOLoop.current()
try:
app.listen(8888)
iol.start()
except KeyboardInterrupt:
iol.stop()
Running this application and retrieving the /status
resource returns
the following:
HTTP/1.1 200 OK
Content-Length: 62
Etag: "e7bca140bba5af0fdb7b9e4fab6487186d7739d2"
Content-Type: application/json
Server: TornadoServer/4.4.2
Date: Mon, 20 Feb 2017 12:54:47 GMT
{"status": "ok", "version": "1.1.1", "name": "my-app-name"}
If your application is a python package, then you can let the status handler do the work of looking up your application's name and version number from the python package metadata.
from tornado import ioloop, web
import sprockets_status.handlers
def make_app(**settings):
return web.Application([
web.url('/status', sprockets_status.handlers.StatusHandler,
{'package': 'my-app'}),
# add your handlers here
], **settings)
if __name__ == '__main__':
app = make_app()
iol = ioloop.IOLoop.current()
try:
app.listen(8888)
iol.start()
except KeyboardInterrupt:
iol.stop()
The status handler will use pkg_resources
to look up the named
distribution and retrieve the package name and version for you. If you
give it a package that doesn't exist, then it will return a server error
so don't do that.
python3.5 -mvenv --copies env
env/bin/pip install -r requires/development.txt -e .
env/bin/nosetests
env/bin/python setup.py build_sphinx