Compare commits
2 Commits
1dc1b8154b
...
db0d1fb6a5
| Author | SHA1 | Date | |
|---|---|---|---|
| db0d1fb6a5 | |||
| be9f2825df |
@@ -60,7 +60,10 @@ async def get_cursors(cursor_id: str) -> CachedCursorOut:
|
|||||||
)
|
)
|
||||||
async def close_all_cursor() -> None:
|
async def close_all_cursor() -> None:
|
||||||
for cached_cursor in mysql.cached_cursors.values():
|
for cached_cursor in mysql.cached_cursors.values():
|
||||||
|
try:
|
||||||
await cached_cursor.close()
|
await cached_cursor.close()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error closing a cursor {e}")
|
||||||
mysql.cached_cursors.clear()
|
mysql.cached_cursors.clear()
|
||||||
|
|
||||||
|
|
||||||
@@ -73,8 +76,11 @@ async def close_cursor(cursor_id: str) -> None:
|
|||||||
cached_cursor = mysql.cached_cursors.get(cursor_id, None)
|
cached_cursor = mysql.cached_cursors.get(cursor_id, None)
|
||||||
if cached_cursor is None:
|
if cached_cursor is None:
|
||||||
raise CursorNotFound
|
raise CursorNotFound
|
||||||
|
try:
|
||||||
await cached_cursor.close()
|
await cached_cursor.close()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error closing the cursor. e={e}")
|
||||||
|
|
||||||
del mysql.cached_cursors[cursor_id]
|
del mysql.cached_cursors[cursor_id]
|
||||||
|
|
||||||
|
|
||||||
@@ -83,11 +89,12 @@ async def close_cursor(cursor_id: str) -> None:
|
|||||||
dependencies=[Depends(get_current_user)],
|
dependencies=[Depends(get_current_user)],
|
||||||
status_code=status.HTTP_200_OK,
|
status_code=status.HTTP_200_OK,
|
||||||
)
|
)
|
||||||
async def cursor_push_ttl(cursor_id: str, new_ttl: int|None=None) -> CachedCursorOut:
|
async def cursor_push_ttl(
|
||||||
|
cursor_id: str, new_ttl: int | None = None
|
||||||
|
) -> CachedCursorOut:
|
||||||
cached_cursor = mysql.cached_cursors.get(cursor_id, None)
|
cached_cursor = mysql.cached_cursors.get(cursor_id, None)
|
||||||
if cached_cursor is None:
|
if cached_cursor is None:
|
||||||
raise CursorNotFound
|
raise CursorNotFound
|
||||||
cached_cursor.ttl = new_ttl if new_ttl else cached_cursor.ttl
|
cached_cursor.ttl = new_ttl if new_ttl else cached_cursor.ttl
|
||||||
cached_cursor.close_at = cached_cursor.upgrade_close_at()
|
cached_cursor.close_at = cached_cursor.upgrade_close_at()
|
||||||
return cached_cursor
|
return cached_cursor
|
||||||
|
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ class SelectQueryInDB(SelectQueryIn):
|
|||||||
|
|
||||||
|
|
||||||
class SelectResultData(BaseModel):
|
class SelectResultData(BaseModel):
|
||||||
columns: List[str]
|
columns: List[str] | str
|
||||||
data: List[List[Any]]
|
data: List[List[Any]]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ async def close_old_cached_cursors():
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await cursor.close()
|
|
||||||
cached_cursors.pop(cursor_id, None)
|
cached_cursors.pop(cursor_id, None)
|
||||||
|
await cursor.close()
|
||||||
closed_cached_cursors[cursor_id] = cursor
|
closed_cached_cursors[cursor_id] = cursor
|
||||||
print(f"Closed cursor {cursor_id}")
|
print(f"Closed cursor {cursor_id}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -51,13 +51,18 @@ async def remove_old_closed_cached_cursors():
|
|||||||
async def cached_cursors_cleaner():
|
async def cached_cursors_cleaner():
|
||||||
global cached_cursors, closed_cached_cursors
|
global cached_cursors, closed_cached_cursors
|
||||||
while True:
|
while True:
|
||||||
|
try:
|
||||||
await close_old_cached_cursors()
|
await close_old_cached_cursors()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error closing some cached cursors, {e=}")
|
||||||
|
try:
|
||||||
await remove_old_closed_cached_cursors()
|
await remove_old_closed_cached_cursors()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error removing closed cursors, {e=}")
|
||||||
await asyncio.sleep(10)
|
await asyncio.sleep(10)
|
||||||
|
|
||||||
|
|
||||||
async def pool_creator(connection: Connection, minsize=5, maxsize=10):
|
async def pool_creator(connection: Connection, minsize=5, maxsize=10):
|
||||||
|
|
||||||
return await aiomysql.create_pool(
|
return await aiomysql.create_pool(
|
||||||
host=connection.host,
|
host=connection.host,
|
||||||
user=connection.username,
|
user=connection.username,
|
||||||
|
|||||||
Reference in New Issue
Block a user