lookingglass/hyperglass/api/events.py
2020-09-28 12:37:44 -07:00

27 lines
637 B
Python

"""API Events."""
# Project
from hyperglass.util import check_redis
from hyperglass.exceptions import HyperglassError
from hyperglass.configuration import REDIS_CONFIG, params
async def _check_redis():
"""Ensure Redis is running before starting server.
Raises:
HyperglassError: Raised if Redis is not running.
Returns:
{bool} -- True if Redis is running.
"""
try:
await check_redis(db=params.cache.database, config=REDIS_CONFIG)
except RuntimeError as e:
raise HyperglassError(str(e), level="danger") from None
return True
on_startup = (_check_redis,)
on_shutdown = ()