core/server.py

31 lines
733 B
Python
Raw Normal View History

2024-05-06 21:06:31 +00:00
import subprocess
from granian.constants import Interfaces
2024-08-12 08:00:01 +00:00
from granian.log import LogLevels
from granian.server import Granian
2024-05-06 21:06:31 +00:00
2024-02-21 20:14:06 +00:00
from settings import PORT
2024-08-09 06:37:06 +00:00
from utils.logger import root_logger as logger
2024-02-21 20:14:06 +00:00
2024-05-06 07:53:27 +00:00
def is_docker_container_running(name):
2024-05-06 07:53:27 +00:00
cmd = ["docker", "ps", "-f", f"name={name}"]
output = subprocess.run(cmd, capture_output=True, text=True).stdout
2024-05-06 07:58:31 +00:00
logger.info(output)
return name in output
2024-05-06 07:53:27 +00:00
2024-04-17 15:32:23 +00:00
if __name__ == "__main__":
logger.info("started")
granian_instance = Granian(
"main:app",
address="0.0.0.0", # noqa S104
port=PORT,
2024-08-12 08:00:01 +00:00
interface=Interfaces.ASGI,
threads=4,
websockets=False,
2024-08-12 08:00:01 +00:00
log_level=LogLevels.debug,
)
2024-05-06 07:53:27 +00:00
granian_instance.serve()