Retry dbcommit

For some reason, Kodi doesn't always trigger the video database scan
stopped event keeping the add-on waiting forever. Try committing after
10 sec and catching the error if the database is truly locked.
This commit is contained in:
angelblue05 2016-10-03 18:59:10 -05:00
parent 04d9effb4b
commit fdc62aa623

View file

@ -192,12 +192,17 @@ class LibrarySync(threading.Thread):
def dbCommit(self, connection): def dbCommit(self, connection):
# Central commit, verifies if Kodi database update is running # Central commit, verifies if Kodi database update is running
kodidb_scan = window('emby_kodiScan') == "true" kodidb_scan = window('emby_kodiScan') == "true"
count = 0
while kodidb_scan: while kodidb_scan:
log.info("Kodi scan is running. Waiting...") log.info("Kodi scan is running. Waiting...")
kodidb_scan = window('emby_kodiScan') == "true" kodidb_scan = window('emby_kodiScan') == "true"
if count == 10:
log.info("Flag still active, but will try to commit")
window('emby_kodiScan', clear=True)
if self.shouldStop(): if self.shouldStop():
log.info("Commit unsuccessful. Sync terminated.") log.info("Commit unsuccessful. Sync terminated.")
break break
@ -206,9 +211,18 @@ class LibrarySync(threading.Thread):
# Abort was requested while waiting. We should exit # Abort was requested while waiting. We should exit
log.info("Commit unsuccessful.") log.info("Commit unsuccessful.")
break break
else:
count += 1
try:
connection.commit() connection.commit()
log.info("Commit successful.") log.info("Commit successful.")
except sqlite3.OperationalError as error:
log.error(error)
if "database is locked" in error:
log.info("retrying...")
window('emby_kodiScan', value="true")
self.dbCommit(connection)
def fullSync(self, manualrun=False, repair=False): def fullSync(self, manualrun=False, repair=False):
# Only run once when first setting up. Can be run manually. # Only run once when first setting up. Can be run manually.