Skip to content

Commit

Permalink
work with semaphore
Browse files Browse the repository at this point in the history
  • Loading branch information
extreme4all committed Nov 26, 2024
1 parent 7067881 commit 54b6fea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/core/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import asyncio

from dotenv import find_dotenv, load_dotenv
from pydantic_settings import BaseSettings

Expand All @@ -13,3 +15,5 @@ class Settings(BaseSettings):


settings = Settings()

DB_SEMAPHORE = asyncio.Semaphore(100)
6 changes: 4 additions & 2 deletions src/core/fastapi/dependencies/session.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from sqlalchemy.ext.asyncio import AsyncSession

from src.core.config import DB_SEMAPHORE
from src.core.database.database import SessionFactory


# Dependency to get an asynchronous session
async def get_session() -> AsyncSession:
async with SessionFactory() as session:
yield session
async with DB_SEMAPHORE: # Acquire semaphore before accessing the session
async with SessionFactory() as session:
yield session # Provide the session to the calling function

0 comments on commit 54b6fea

Please sign in to comment.