Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a decorator #21

Open
luiscoms opened this issue Oct 28, 2019 · 2 comments · May be fixed by #25
Open

Create a decorator #21

luiscoms opened this issue Oct 28, 2019 · 2 comments · May be fixed by #25

Comments

@luiscoms
Copy link
Member

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

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

@syndicut
Copy link

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

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

@luiscoms
Copy link
Member Author

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)),
])

funilrys added a commit to funilrys/py-healthcheck that referenced this issue Oct 30, 2019
This patch fix #ateliedocodigo#21

What has been done?

1. Added the healthcheck/wrappers.py file/submodule.
2. Added the `wrappers.add_check_to` wrapper.
3. Added the `wrappers.add_section_to` wrapper.
4. Increased the version number into `setup.py`.

About `wrappers.add_check_to`:

As I do not want to create a global variable, or a unify the way to
reference to the `HealthCheck` class, I made it clear that it is needed
as reference. If it's not the intended behavior, let me know.

  Note: It raises an exception if it get an input class which is not
  `HealthCheck`.

About `wrappers.add_section_to`:

As I do not want to create a global variable, or unify the way we
reference to `HealthCheck` or `EnvironmentDump`, I made it clear that
one of them is needed. The second argument is the name of the section
(nothing new).

  Note: It raises an exception if it get an input class which is not
  `HealthCheck` or `EnvironmentDump`.
@luiscoms luiscoms linked a pull request Jun 10, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants