首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >集成代码之前的GitLab健康端点

集成代码之前的GitLab健康端点
EN

Stack Overflow用户
提问于 2021-12-13 10:37:07
回答 1查看 501关注 0票数 2

我刚开始部署ML模型,我想部署一个包含几个模块的模型,每个模块都由包含一些数据文件、.py脚本和一个Python记事本的“文件夹”组成。

我在GitLab中创建了一个项目,并且我试图遵循关于FastAPI的教程,因为这是我将要使用的。但是有人告诉我,在我开始集成代码之前,我需要设置一个健康端点。

我知道请求curl "https://gitlab.example.com/-/health",但是我需要设置什么吗?在执行requirements.txt、构建应用程序的框架等之前,我还需要为项目设置做些什么吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-12-13 10:52:24

它完全取决于您的需要,没有在fastapi中本地实现的健康端点。

但是有人告诉我,在我开始集成代码之前,我需要设置一个健康端点。

不一定是一个坏的做法,你可以从列出所有的未来健康检查,并从那里建立你的路线。

评论中的最新情况:

但我不知道该怎么实现。我需要配置文件吗?我对这件事很陌生。

据我所知,您对python非常陌生,因此您应该从遵循官方快速表用户指南开始。您还可以从第一步跟踪

运行如下的一个非常基本的文件项目:

代码语言:javascript
复制
# main.py

from fastapi import FastAPI

app = FastAPI()

@app.get("/health")
async def root():
    return {"message": "Alive!"}

请记住,上面的内容不适合于生产,只适用于测试/学习目的,要制作一个生产api,您应该遵循官方的高级用户指南并实现如下内容。

更高级的路由器:

你有this health lib的fastapi,这太好了。

您可以这样进行基本检查:

代码语言:javascript
复制
# app.routers.health.py
from fastapi import APIRouter, status, Depends
from fastapi_health import health

from app.internal.health import healthy_condition, sick_condition

router = APIRouter(
    tags=["healthcheck"],
    responses={404: {"description": "not found"}},
)


@router.get('/health', status_code=status.HTTP_200_OK)
def perform_api_healthcheck(health_endpoint=Depends(health([healthy_condition, sick_condition]))):
    return health_endpoint
代码语言:javascript
复制
# app.internal.health.py
def healthy_condition():  # just for testing puposes
    return {"database": "online"}


def sick_condition():  # just for testing puposes
    return True
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70333286

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档