1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

move redis check into app file

This commit is contained in:
checktheroads
2019-12-30 09:44:29 -07:00
parent 590ab2aa59
commit e79968194a

View File

@ -11,36 +11,17 @@ def _logger():
return _loguru_logger
async def check_redis(host, port):
"""Validate if Redis is running.
def cpu_count():
"""Get server's CPU core count.
Arguments:
host {str} -- IP address or hostname of Redis server
port {[type]} -- TCP port of Redis server
Raises:
ConfigInvalid: Raised if redis server is unreachable
Used for number of web server workers.
Returns:
{bool} -- True if running, False if not
{int} -- CPU Cores
"""
import asyncio
from socket import gaierror
from hyperglass.exceptions import ConfigInvalid
import multiprocessing
try:
_reader, _writer = await asyncio.open_connection(str(host), int(port))
except gaierror:
raise ConfigInvalid(
"Redis isn't running: {host}:{port} is unreachable/unresolvable.",
alert="danger",
host=host,
port=port,
)
if _reader or _writer:
return True
else:
return False
return multiprocessing.cpu_count()
log = _logger()