시장 조사 llm 추가 및 파이프라인 정리, db 커넥션 풀 문제 처리

This commit is contained in:
jaehwang committed 2026-05-19 15:22:34 +09:00
1 parent 42e09ae2d1
commit cda518c027
13 files changed
+328 -65

No files matched your search

+25 -9
View File
@@ -26,22 +26,38 @@ async def get_pool() -> aiomysql.Pool:
# 쓰기 (INSERT/UPDATE/DELETE)
async def execute(sql: str, args: tuple = ()) -> int:
pool = await get_pool()
print(
f"[Pool] size={pool.size} "
f"free={pool.freesize} "
f"used={pool.size - pool.freesize} "
f"max={pool.maxsize}"
)
async with pool.acquire() as conn:
await conn.ping(reconnect=True)
async with conn.cursor() as cur:
await cur.execute(sql, args)
await conn.commit()
return cur.lastrowid
try:
async with conn.cursor() as cur:
await cur.execute(sql, args)
await conn.commit()
return cur.lastrowid
finally:
conn.close()
# 읽기 (SELECT)
async def fetchone(sql: str, args: tuple = ()) -> dict | None:
pool = await get_pool()
print(
f"[Pool] size={pool.size} "
f"free={pool.freesize} "
f"used={pool.size - pool.freesize} "
f"max={pool.maxsize}"
)
async with pool.acquire() as conn:
await conn.ping(reconnect=True)
async with conn.cursor(aiomysql.DictCursor) as cur:
await cur.execute(sql, args)
return await cur.fetchone()
try:
async with conn.cursor(aiomysql.DictCursor) as cur:
await cur.execute(sql, args)
return await cur.fetchone()
finally:
conn.close()
async def insert_instagram_row(hospital_id: str, url: str) -> int:
return await execute("INSERT INTO instagram_data (hospital_id, url) VALUES (%s, %s)", (hospital_id, url))