File size: 1,395 Bytes
8675ade
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f6b0edc
8675ade
 
 
 
 
 
 
 
 
 
 
f6b0edc
8675ade
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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())