[英]Falcon API - check if the server is running
I have built a very simple API in Falcon that post results of my machine learning model.我在 Falcon 中构建了一个非常简单的 API,用于发布我的机器学习模型的结果。 See below:见下文:
import falcon
import heureka_predikce
class MLmodel:
def on_post(self, req, resp):
reg_list = req.media
response_list = []
for vstup in reg_list:
response_list.append(heureka_predikce.heureka_predikuj(vstup))
resp.text = response_list
resp.status = falcon.HTTP_OK
my_model = MLmodel()
app = application = falcon.API()
app.add_route("/predictionApi/v1/predict", my_model)
But I would like to check if the server is running.但我想检查服务器是否正在运行。 That is, I would like to include some new method into MLmodel
that does a "health check".也就是说,我想在MLmodel
中加入一些新方法来进行“健康检查”。 I am a beginner with APIs, but is there a recommended way, how to do this?我是 API 的初学者,但是有推荐的方法吗,怎么做? I think that it should be relatively easy, but I cannot find anything myself... Thanks我认为它应该相对容易,但我自己找不到任何东西......谢谢
To check if server is up and running, usually what we do is send a request at an endpoint and server will return something indicating that it's working.要检查服务器是否启动并运行,通常我们所做的是在端点发送请求,服务器将返回表明它正在工作的内容。
As you said you will need to add a method in MLmodel
for the same reason, it can be done but it's not the recommended way as your MLmodel
is handling predict
endpoint.正如您所说,出于同样的原因,您将需要在MLmodel
中添加一个方法,可以这样做,但这不是推荐的方法,因为您的MLmodel
正在处理predict
端点。
To do a health check, you can create a new endpoint with new class which will accept a get
request and will respond you as soon it is invoked.要进行健康检查,您可以使用新类创建一个新端点,该端点将接受get
请求并在调用它时立即响应您。
For Ex.:例如:
class Ping:
def on_get(self, req, resp):
resp.text = "pong"
resp.status = falcon.HTTP_OK
And then just add route for same resource using: app.add_route("/predictionApi/v1/ping", Ping())
然后只需使用以下方法为同一资源添加路由: app.add_route("/predictionApi/v1/ping", Ping())
Now for each ping request, you will get pong response.现在对于每个 ping 请求,您都会得到 pong 响应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.