1
0
mirror of https://github.com/moparisthebest/SickRage synced 2025-01-07 11:58:01 -05:00

Fix for db locking issues

This commit is contained in:
echel0n 2014-06-05 09:22:54 -07:00
parent f052848e52
commit d30060bf91

View File

@ -22,6 +22,7 @@ import os.path
import re import re
import threading import threading
import sqlite3 import sqlite3
import time
import sickbeard import sickbeard
from sqlalchemy import create_engine, exc from sqlalchemy import create_engine, exc
@ -102,7 +103,7 @@ class DBConnection:
if "unable to open database file" in e.args[0] or "database is locked" in e.args[0]: if "unable to open database file" in e.args[0] or "database is locked" in e.args[0]:
logger.log(u"DB error: " + ex(e), logger.WARNING) logger.log(u"DB error: " + ex(e), logger.WARNING)
attempt += 1 attempt += 1
#time.sleep(cpu_presets[sickbeard.CPU_PRESET]) time.sleep(1)
else: else:
logger.log(u"DB error: " + ex(e), logger.ERROR) logger.log(u"DB error: " + ex(e), logger.ERROR)
raise raise
@ -126,17 +127,17 @@ class DBConnection:
while attempt < 5: while attempt < 5:
try: try:
with self.connection as trans: for qu in querylist:
for qu in querylist: if len(qu) == 1:
if len(qu) == 1: if logTransaction:
if logTransaction: logger.log(qu[0], logger.DEBUG)
logger.log(qu[0], logger.DEBUG) sqlResult.append(self.connection.execute(qu[0]))
sqlResult.append(trans.execute(qu[0])) elif len(qu) > 1:
elif len(qu) > 1: if logTransaction:
if logTransaction: logger.log(qu[0] + " with args " + str(qu[1]), logger.DEBUG)
logger.log(qu[0] + " with args " + str(qu[1]), logger.DEBUG) sqlResult.append(self.connection.execute(qu[0], qu[1]))
sqlResult.append(trans.execute(qu[0], qu[1]))
self.connection.commit()
logger.log(u"Transaction with " + str(len(querylist)) + u" queries executed", logger.DEBUG) logger.log(u"Transaction with " + str(len(querylist)) + u" queries executed", logger.DEBUG)
return sqlResult return sqlResult
except sqlite3.OperationalError, e: except sqlite3.OperationalError, e:
@ -146,6 +147,7 @@ class DBConnection:
if "unable to open database file" in e.args[0] or "database is locked" in e.args[0]: if "unable to open database file" in e.args[0] or "database is locked" in e.args[0]:
logger.log(u"DB error: " + ex(e), logger.WARNING) logger.log(u"DB error: " + ex(e), logger.WARNING)
attempt += 1 attempt += 1
time.sleep(1)
else: else:
logger.log(u"DB error: " + ex(e), logger.ERROR) logger.log(u"DB error: " + ex(e), logger.ERROR)
raise raise
@ -182,7 +184,7 @@ class DBConnection:
if "unable to open database file" in e.args[0] or "database is locked" in e.args[0]: if "unable to open database file" in e.args[0] or "database is locked" in e.args[0]:
logger.log(u"DB error: " + ex(e), logger.WARNING) logger.log(u"DB error: " + ex(e), logger.WARNING)
attempt += 1 attempt += 1
#time.sleep(cpu_presets[sickbeard.CPU_PRESET]) time.sleep(1)
else: else:
logger.log(u"DB error: " + ex(e), logger.ERROR) logger.log(u"DB error: " + ex(e), logger.ERROR)
raise raise