Error handled cursors closing
This commit is contained in:
@@ -60,7 +60,10 @@ async def get_cursors(cursor_id: str) -> CachedCursorOut:
|
||||
)
|
||||
async def close_all_cursor() -> None:
|
||||
for cached_cursor in mysql.cached_cursors.values():
|
||||
await cached_cursor.close()
|
||||
try:
|
||||
await cached_cursor.close()
|
||||
except Exception as e:
|
||||
print(f"Error closing a cursor {e}")
|
||||
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)
|
||||
if cached_cursor is None:
|
||||
raise CursorNotFound
|
||||
try:
|
||||
await cached_cursor.close()
|
||||
except Exception as e:
|
||||
print(f"Error closing the cursor. e={e}")
|
||||
|
||||
await cached_cursor.close()
|
||||
del mysql.cached_cursors[cursor_id]
|
||||
|
||||
|
||||
@@ -83,11 +89,12 @@ async def close_cursor(cursor_id: str) -> None:
|
||||
dependencies=[Depends(get_current_user)],
|
||||
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)
|
||||
if cached_cursor is None:
|
||||
raise CursorNotFound
|
||||
cached_cursor.ttl = new_ttl if new_ttl else cached_cursor.ttl
|
||||
cached_cursor.close_at = cached_cursor.upgrade_close_at()
|
||||
return cached_cursor
|
||||
|
||||
|
||||
Reference in New Issue
Block a user