Skip to main content

Healthchecks Decorator

Project description

PyPI Status Python Version License

Read the documentation at https://healthchecks-decorator.readthedocs.io/ Tests Codecov

pre-commit Black

A simple python decorator for healthchecks.io.

Features

The healthchecks-decorator library provides the following features:

  • 🚀 Easy to use: Simply decorate your function with @healthcheck to enable health checks.

  • ⏲️ Execution time measurement: Supports sending /start signals to measure job execution times.

  • 🔥 Exception handling: Automatically sends /failure signals when jobs produce exceptions.

  • 🤖 Auto-provisioning: Supports automatic provisioning of new health checks by adding ?create=1 to the ping URL.

  • 🌡️ Diagnostics information: Send diagnostics information to help diagnose issues.

  • 😊 Flexible endpoint support: Supports both SaaS and self-hosted endpoints.

Requirements

  • None - just 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

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

healthchecks_decorator-0.5.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

healthchecks_decorator-0.5.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file healthchecks_decorator-0.5.0.tar.gz.

File metadata

  • Download URL: healthchecks_decorator-0.5.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.5

File hashes

Hashes for healthchecks_decorator-0.5.0.tar.gz
Algorithm Hash digest
SHA256 5b6cc59a1e8a9558e365a9c14cbf34182f1545a488254e35e782ad95259908a5
MD5 25ef3e4506f4c88a1173e11df1b5188a
BLAKE2b-256 eec46e5015dcf86a00fe213216c531e8e8ae40ba777585f1bdb6427f00476228

See more details on using hashes here.

File details

Details for the file healthchecks_decorator-0.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for healthchecks_decorator-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2331f263be0278fa00c1e3438a50bc04b37e6b306e2b065cfd86db20d0521852
MD5 614d9c5b754fcfcc8261827ede6dd63e
BLAKE2b-256 12bc8e083e2b3aafd3c2f026f0fc5b03784e2b375b47c47a5283c9de257f8d7a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page