Retry transaction until it works
This commit is contained in:
parent
1fee49d0e4
commit
6b1348236d
1 changed files with 8 additions and 1 deletions
|
|
@ -1,16 +1,23 @@
|
|||
import asyncio
|
||||
import logging
|
||||
import sqlite3
|
||||
|
||||
from .utils import *
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
__all__ = ["Database", "operation"]
|
||||
|
||||
|
||||
def operation(func):
|
||||
async def wrapper(self, *args, **kwargs):
|
||||
async with self as db:
|
||||
return await asyncify(func, self, db, *args, **kwargs)
|
||||
while True:
|
||||
try:
|
||||
return await asyncify(func, self, db, *args, **kwargs)
|
||||
except sqlite3.OperationalError as e:
|
||||
logger.warn(f"Operational error encountered: {e}")
|
||||
await asyncio.sleep(5)
|
||||
return wrapper
|
||||
|
||||
class Database:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue