Coverage for model/health.py: 100%
16 statements
« prev ^ index » next coverage.py v7.3.2, created at 2024-11-05 04:22 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2024-11-05 04:22 +0000
1from flask import Blueprint
2from pymongo import MongoClient
4from .utils import *
5from mongo.utils import RedisCache
6from mongo.engine import MONGO_HOST
8__all__ = ('health_api', )
10health_api = Blueprint('health_api', __name__)
13@health_api.route('/')
14def health():
15 # Check mongo
16 client = MongoClient(MONGO_HOST)
17 mongo_ok = client.server_info().get('ok', 0) == 1.0
18 # Check redis
19 redis_ok = RedisCache().client.ping()
20 noj_ok = mongo_ok and redis_ok
21 if noj_ok:
22 return HTTPResponse()
23 else:
24 return HTTPError(
25 message='Service is not available',
26 status_code=500,
27 data={
28 'mongo': mongo_ok,
29 'redis': redis_ok
30 },
31 )