轻松创建运行状况检查的终结点

django-healthpoint的Python项目详细描述


https://badge.fury.io/py/django-healthpoint.pnghttps://travis-ci.org/pennersr/django-healthpoint.pnghttps://img.shields.io/pypi/v/django-healthpoint.svgCoverage Statushttps://pennersr.github.io/img/bitcoin-badge.svg

用于向项目中添加运行状况检查终结点的框架。

源代码
http://github.com/pennersr/django-healthpoint

快速启动

安装应用程序:

# settings.py
INSTALLED_APPS = [
    ...
    'healthpoint'
]

# If specified, this user is able to see the details for each
# individual check in the endpoint.
HEALTHPOINT_BASICAUTH_USERNAME = 'john'
HEALTHPOINT_BASICAUTH_PASSWORD = 'doe'

# urls.py
urlpatterns = [
    ...
    url(r'^', include('healthpoint.urls')),
]

将名为health.py的模块添加到任何应用程序中。例如:

from datetime import timedelta

from django.contrib.auth.models import User
from django.utils import timezone

from healthpoint.decorators import health_check


@health_check
def user_signup():
    last_user = User.objects.last()
    time_since_last_signup = timezone.now() - last_user.date_joined
    # Return True/False, throw an exception, or return a tuple with a
    # detail message.
    return (
        time_since_last_signup <= timedelta(days=1),
        "last signup was: {}".format(last_user.date_joined))

可以通过/health/端点访问运行状况检查:

  • 它执行所有运行状况检查,如果所有检查成功,则报告状态200,否则报告状态500。

  • 如果员工用户已登录,则端点将报告每个单独检查的结果:

    {
     "success": {},
     "error": {
       "myproject.myapp.health.user_signup": "Last signup was: 2017-10-29 08:45:51"
     }
    }
    
  • 为了提供有关结果的更多详细信息,@health_check可以返回一个元组(success:bool, detail:str)。详细信息将列在结果中。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何将异步类的结果放入mainActivity EditText   java LDAP目录管理器服务提供,OutOfMemory   java Cassandra NoHostAvailableException,但仍存在活动节点   springboot应用程序的java启动线程   如果poll不一定返回第一项,那么java是ConcurrentLinkedQueue的好选择吗?   解析XML时JSON中出现java意外字符串   当'key'是两个整数时,如何输出Java HashMap键?   java为什么不显示在jsp页面中   java使用流式API转换映射列表中的值   JavaJPA+Spring:基于在持久化实体之前接收到的值,将外键列映射到ID   java如何使用selenium读取pdf文件   Canny之后的java对象提取   DSpace没有列出集合,java。lang.NumberFormatException:null   java我可以为数据库表主键设置一个最大值吗?   java如何定义Javadoc链接,可以通过单击   @java/spring中的SessionAttribute是否丢失数据?