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

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第三方库


热门话题
ArrayList Java中的搜索字符串   另一个web应用程序的java访问会话   另一个应用程序中的活动和服务之间的java通信   java根据Json字符串类型将Json字符串转换为对象   eclipse如何解决java中的错误异常。lang.NoSuchMethodError:'java。字符串javax。摆动JOptionPane。showInputDialog(java.lang.String)'   线程“main”java中的安卓异常。lang.NoClassDefFoundError:org/codehaus/jackson/JsonParseException   java如何在安卓 emulator上显示Mat图像?使用NDK   Java在本地读取测试源文件,但在服务器上读取失败   java dowhile循环用于计算输入数字中的数字。故障排除代码   JAva初学者在编写获取成本的方法时遇到困难   java是shell游戏。我如何让物体移动,特别是在特定的曲线上,但顺序是随机的?   java如何区分两个同名的JButton   java为什么我在Spring Boot中需要一个接口?   java将文件路径插入数据库将删除\   使用InterfaceType初始化java对象   java如何部署一个分为Angular、Spring Boot和MySQL的项目?   java如何使用Symja解决不等式?