I am trying to add health liveness and readiness into Flask API as follows:
from flask import Flask
from flask_healthz import healthz
from flask_healthz import HealthError
app = Flask(__name__)
app.register_blueprint(healthz, url_prefix="/healthz")
def printok():
print("Everything is fine")
def liveness():
try:
printok()
except Exception:
raise HealthError("Can't connect to the file")
def readiness():
try:
printok()
except Exception:
raise HealthError("Can't connect to the file")
app.config.update(
HEALTHZ = {
"live": "app.liveness",
"ready": "app.readiness",
}
)
@app.route("/")
def hello():
return "Hello World"
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
but when I run curl to check it, I get the error "The live function could not be imported":
$ curl localhost:5000/healthz/live
{"status": 500, "title": "The live check function could not be imported"}
or
$ curl localhost:5000/healthz/ready
{"status": 500, "title": "The ready check function could not be imported"}
it is interesting that this example has already been suggested by this link healthz for flask as working
Any idea why this error occurs? and how can I resolve it?