Healthchecks Decorator
Project description
A simple python decorator for healthchecks.io.
Features
Just decorate your function with @healthcheck 🚀.
Support sending /start signals to measure job execution times ⏲️.
Automatic /failure signals when jobs produce exceptions 🔥.
Send diagnostics information 🌡️.
Support both SaaS and self-hosted endpoints 😊.
Requirements
None - only pure python 🐍.
Installation
You can install Healthchecks Decorator via pip from PyPI:
$ pip install healthchecks-decorator
Usage
Basic usage
from healthchecks_decorator import healthcheck
@healthcheck(url="https://hc-ping.com/<uuid1>")
def job():
"""Job with a success healthcheck signal when done"""
pass
@healthcheck(url="https://hc-ping.com/<uuid2>", send_start=True)
def job_with_start():
"""Send also a /start signal before starting"""
pass
@healthcheck(url="https://hc-ping.com/<uuid3>")
def job_with_exception():
"""This will produce a /fail signal"""
raise Exception("I'll be propagated")
@healthcheck(url="https://hc-ping.com/<uuid4>", send_diagnostics=True)
def job_with_diagnostics():
"""Send the returned value in the POST body.
The returned value must be a valid input for `urllib.parse.urlencode`.
Otherwise, nothing will be sent."""
return {"temperature": -7}
Environment variables
It is possible to set options through environment variables. Each option has a corresponding environment variable defined by the option name in upper snake case with the HEALTHCHECK_ prefix.
For example, setting:
HEALTHCHECK_URL=http://fake-hc.com/uuid
HEALTHCHECK_SEND_DIAGNOSTICS=TRUE
HEALTHCHECK_SEND_START=1
will allow having the most minimalist usage:
@healthcheck
def job():
"""Url, send_diagnostics and send_start are grabbed from environment."""
pass
Please see the Documentation for details.
Contributing
Contributions are very welcome. To learn more, see the Contributor Guide.
License
Distributed under the terms of the MIT license, Healthchecks Decorator is free and open source software.
Issues
If you encounter any problems, please file an issue along with a detailed description.
Credits
This project was generated from @cjolowicz’s Hypermodern Python Cookiecutter template.
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
Built Distribution
Hashes for healthchecks-decorator-0.4.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64b082d5247d1155c8142172b2d74901421051102c585640a2e765e3dba441c8 |
|
MD5 | a8b01d8a4b937d737a5ba89c30fd6378 |
|
BLAKE2b-256 | a5e96fbbc2c215e40bd9bcbe4d529ad2be75620f4254059a176c48924cdb3c26 |
Hashes for healthchecks_decorator-0.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88bf4613a708632d99dd51c9cc911178768f4a42e860a17ed9a591d7401d2768 |
|
MD5 | f94d431d4d11b8b28a29ad0044a6c75d |
|
BLAKE2b-256 | 3945282c4ca903996232ec7a9104c431fb7dac48f8d9036bf162c48048e465d1 |