2020-01-21 17:27:57 -07:00
|
|
|
"""API Events."""
|
|
|
|
|
2020-04-16 00:27:00 -07:00
|
|
|
# Project
|
|
|
|
from hyperglass.log import log
|
|
|
|
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
|
|
|
|
|
|
|
|
log.debug(f"Redis is running at: {REDIS_CONFIG['host']}:{REDIS_CONFIG['port']}")
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
on_startup = (_check_redis,)
|
|
|
|
on_shutdown = ()
|