-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
59 lines (43 loc) · 1.42 KB
/
main.py
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
49
50
51
52
53
54
55
56
57
58
59
import os
import dotenv
import uvicorn
import inspect
from loguru import logger
from fastapi import FastAPI
from sqlalchemy import inspect as sqlalchemy_inspect
env = os.getenv("ENVIRONMENT", "local")
(
dotenv.load_dotenv(".env.docker")
if env == "docker"
else dotenv.load_dotenv(".env.local")
)
# noinspection PyUnresolvedReferences
from src.recommendation_engine.app.shared_kernel.scheduler.celery_app import (
celery_application,
)
# noinspection PyUnresolvedReferences
from src.recommendation_engine.app.tasks import *
# noinspection PyUnresolvedReferences
from src.recommendation_engine.app.shared_kernel.database.clickhouse import (
ClickhouseBase,
engine,
)
# noinspection PyUnresolvedReferences
from src.recommendation_engine.app import *
app = FastAPI()
def create_tables():
inspector = sqlalchemy_inspect(engine)
for name, obj in globals().items():
if inspect.isclass(obj):
if issubclass(obj, ClickhouseBase) and obj != ClickhouseBase:
if not inspector.has_table(obj.__tablename__):
obj.__table__.create(engine)
logger.info(f"{name} Clickhouse Table Created.")
else:
logger.info(f"{name} Clickhouse Table Already Exists.")
@app.get("/")
def hello_world():
return "hello world"
if __name__ == "__main__":
create_tables()
uvicorn.run("main:app", host="0.0.0.0", port=8000)