api 의존성 추가 및 DB 설정 변경
This commit is contained in:
1 parent
f008ed4010
commit
ab4dc6fb81
5 files changed
+37
-4
No files matched your search
+3
-1
@@ -5,11 +5,13 @@ from fastapi import FastAPI
|
||||
from pipelines import worker
|
||||
from routers import f1, playreel
|
||||
from utils import blob
|
||||
from utils.database import close_engine
|
||||
from utils.database import close_engine, create_missing_tables
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
# 테이블 정의는 tables.task 를 임포트한 라우터·파이프라인이 이미 등록해 둔다
|
||||
await create_missing_tables()
|
||||
worker.start()
|
||||
yield
|
||||
await worker.stop()
|
||||
|
||||
@@ -11,6 +11,7 @@ dependencies = [
|
||||
"openai>=3.6.0",
|
||||
"pillow>=12.3.0",
|
||||
"pydantic-settings>=2.15.0",
|
||||
"python-multipart>=0.0.32",
|
||||
"scipy>=1.18.1",
|
||||
"sqlalchemy>=2.0.52",
|
||||
"uvicorn[standard]>=0.52.4",
|
||||
|
||||
+14
-1
@@ -1,3 +1,5 @@
|
||||
from urllib.parse import quote_plus
|
||||
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
@@ -10,9 +12,20 @@ class Settings(BaseSettings):
|
||||
suno_callback_url: str = "" # Suno가 요구하는 값. 결과는 폴링으로 받는다
|
||||
higgsfield_account: str = "" # CLI 토큰이 이 계정 것인지 확인만 한다
|
||||
|
||||
mysql_url: str = "" # mysql+asyncmy://user:pw@host:3306/db
|
||||
mysql_host: str = ""
|
||||
mysql_port: int = 3306
|
||||
mysql_user: str = ""
|
||||
mysql_password: str = ""
|
||||
mysql_db: str = ""
|
||||
|
||||
azure_blob_base_url: str = ""
|
||||
azure_blob_sas_token: str = ""
|
||||
|
||||
@property
|
||||
def mysql_url(self) -> str:
|
||||
password = quote_plus(self.mysql_password)
|
||||
return (f"mysql+asyncmy://{self.mysql_user}:{password}"
|
||||
f"@{self.mysql_host}:{self.mysql_port}/{self.mysql_db}")
|
||||
|
||||
|
||||
settings = Settings()
|
||||
@@ -7,7 +7,7 @@ from collections.abc import AsyncGenerator
|
||||
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
||||
from sqlalchemy.orm import DeclarativeBase
|
||||
from sqlalchemy.pool import AsyncQueuePool
|
||||
from sqlalchemy.pool import AsyncAdaptedQueuePool
|
||||
|
||||
from settings import settings
|
||||
|
||||
@@ -25,7 +25,7 @@ engine = create_async_engine(
|
||||
settings.mysql_url,
|
||||
pool_size=POOL_SIZE,
|
||||
max_overflow=MAX_OVERFLOW,
|
||||
poolclass=AsyncQueuePool,
|
||||
poolclass=AsyncAdaptedQueuePool,
|
||||
pool_timeout=POOL_TIMEOUT,
|
||||
pool_recycle=POOL_RECYCLE,
|
||||
pool_pre_ping=True, # 끊긴 연결을 쓰기 전에 걸러낸다
|
||||
@@ -54,5 +54,11 @@ async def get_session() -> AsyncGenerator[AsyncSession, None]:
|
||||
raise
|
||||
|
||||
|
||||
async def create_missing_tables() -> None:
|
||||
"""없는 테이블만 만든다. 컬럼이 바뀐 기존 테이블은 건드리지 않는다"""
|
||||
async with engine.begin() as connection:
|
||||
await connection.run_sync(Base.metadata.create_all)
|
||||
|
||||
|
||||
async def close_engine() -> None:
|
||||
await engine.dispose()
|
||||
Generated
+11
@@ -95,6 +95,7 @@ dependencies = [
|
||||
{ name = "openai" },
|
||||
{ name = "pillow" },
|
||||
{ name = "pydantic-settings" },
|
||||
{ name = "python-multipart" },
|
||||
{ name = "scipy" },
|
||||
{ name = "sqlalchemy" },
|
||||
{ name = "uvicorn", extra = ["standard"] },
|
||||
@@ -110,6 +111,7 @@ requires-dist = [
|
||||
{ name = "openai", specifier = ">=3.6.0" },
|
||||
{ name = "pillow", specifier = ">=12.3.0" },
|
||||
{ name = "pydantic-settings", specifier = ">=2.15.0" },
|
||||
{ name = "python-multipart", specifier = ">=0.0.32" },
|
||||
{ name = "scipy", specifier = ">=1.18.1" },
|
||||
{ name = "sqlalchemy", specifier = ">=2.0.52" },
|
||||
{ name = "uvicorn", extras = ["standard"], specifier = ">=0.52.4" },
|
||||
@@ -527,6 +529,15 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/0d/17/c5c6b53ddc18f297992099b3d9ec16c855c0ccc83263a21fe4d1c625ec6c/python_dotenv-1.2.3-py3-none-any.whl", hash = "sha256:904552145e8bfed22162c09dab1c2b9b54fefa7b23ba780f4f26ca0316b0f0d9", size = 22780, upload-time = "2026-08-16T16:54:52.473Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "python-multipart"
|
||||
version = "0.0.32"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/5b/42/55c32bb9b12693c092ad250a0e82edb5b31ddeda6eb772de5f308b3804ad/python_multipart-0.0.32.tar.gz", hash = "sha256:be54b7f3fa167bb83e4fcd936b887b708f4e57fe75911c02aebf53efaf8d938e", size = 46881, upload-time = "2026-06-04T16:18:58.647Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/e1/04/e8135ebd1ad02c56ec633277529b2602ff99ff634be76cdba5744cf554fd/python_multipart-0.0.32-py3-none-any.whl", hash = "sha256:ff6d3f776f16878c894e52e107296ffc890e913c611b1a4ec6c44e2821fe2e23", size = 30042, upload-time = "2026-06-04T16:18:57.319Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pyyaml"
|
||||
version = "6.0.3"
|
||||
|
||||
Reference in new issue
Block a user