py-healthcheck icon indicating copy to clipboard operation
py-healthcheck copied to clipboard

Create a decorator

Open luiscoms opened this issue 4 years ago • 2 comments

Create a decorator @checker in order to add checkers on other modules.

Note: keep in mind that this package supports flask end tornado

luiscoms avatar Oct 28 '19 11:10 luiscoms

I want to have look at this one. Is interface like this ok?

@checker(health: HealthCheck)
def example_checker():
  ...

syndicut avatar Oct 28 '19 16:10 syndicut

No, it should be like this

Flask

from flask import Flask
from healthcheck import checker, HealthCheck

app = Flask(__name__)

health = HealthCheck()

# add your own check function to the healthcheck
@checker
def redis_available():
    client = _redis_client()
    info = client.info()
    return True, "redis ok"

# Add a flask route to expose information
app.add_url_rule("/healthcheck", "healthcheck", view_func=lambda: health.run())

Tornado

import tornado.web
from healthcheck import checker, TornadoHandler, HealthCheck

# add your own check function to the healthcheck
@checker
def redis_available():
    client = _redis_client()
    info = client.info()
    return True, "redis ok"

health = HealthCheck()

app = tornado.web.Application([
    ("/healthcheck", TornadoHandler, dict(checker=health)),
])

luiscoms avatar Oct 28 '19 16:10 luiscoms