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 asyncio
|
||||||
|
import logging
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
from .utils import *
|
from .utils import *
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
__all__ = ["Database", "operation"]
|
__all__ = ["Database", "operation"]
|
||||||
|
|
||||||
|
|
||||||
def operation(func):
|
def operation(func):
|
||||||
async def wrapper(self, *args, **kwargs):
|
async def wrapper(self, *args, **kwargs):
|
||||||
async with self as db:
|
async with self as db:
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
return await asyncify(func, self, db, *args, **kwargs)
|
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
|
return wrapper
|
||||||
|
|
||||||
class Database:
|
class Database:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue