Spaces:
Running
Running
import uvicorn | |
import subprocess | |
import shutil | |
import time | |
import asyncio | |
from src.core.utils import logger, read_config | |
def start_redis_server(redis_config: dict): | |
redis_path = shutil.which("redis-server") | |
if not redis_path: | |
raise RuntimeError("redis-server is not installed or not in PATH") | |
process = subprocess.Popen( | |
[redis_path, "--port", str(redis_config['port']), "--bind", redis_config['host']], | |
stdout=subprocess.DEVNULL, | |
stderr=subprocess.DEVNULL | |
) | |
time.sleep(1) | |
logger.info( | |
f"Redis server started successfully on {redis_config['host']}:{redis_config['port']}", | |
log_type="server", | |
console=True | |
) | |
return process | |
def initialize_config() -> dict: | |
return read_config(config_path="config.yaml") | |
async def main(): | |
config = initialize_config() | |
# redis_process = start_redis_server(redis_config=config['redis_server']) | |
try: | |
uvicorn.run( | |
app="src.core.server:app", | |
host=config['server']['host'], | |
port=config['server']['port'], | |
reload=config['server']['reload'], | |
workers=config['server']['workers'] | |
) | |
finally: | |
logger.info("Shutting down Redis server...", log_type="server", console=config['app']['verbose']) | |
# redis_process.terminate() | |
if __name__ == "__main__": | |
asyncio.run(main()) | |