Skip to content

Commit 9ad92c4

Browse files
authored
Merge pull request #18 from ayoub3bidi/feat/lifespan
refactor(api): lifespan and remove create_all
2 parents c795843 + 4cd5ed5 commit 9ad92c4

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/main.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1+
from contextlib import asynccontextmanager
2+
13
from fastapi import FastAPI
24
from fastapi.middleware.cors import CORSMiddleware
35

46
from constants.settings import settings
57
import database.redis_db as redis
6-
from database.postgres_db import Base, dbEngine
78
from restful_ressources import import_resources
89

9-
Base.metadata.create_all(bind=dbEngine)
10-
redis.init()
10+
11+
@asynccontextmanager
12+
async def lifespan(_app: FastAPI):
13+
redis.init()
14+
yield
15+
1116

1217
_is_production = settings.APP_ENV == "production"
1318

1419
app = FastAPI(
20+
lifespan=lifespan,
1521
docs_url=None if _is_production else "/",
1622
redoc_url=None if _is_production else "/redoc",
1723
openapi_url=None if _is_production else "/openapi.json",

0 commit comments

Comments
 (0)