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
1 changed files with 15 additions and 1 deletions

View File

@ -192,12 +192,17 @@ class LibrarySync(threading.Thread):
def dbCommit(self, connection):
# Central commit, verifies if Kodi database update is running
kodidb_scan = window('emby_kodiScan') == "true"
count = 0
while kodidb_scan:
log.info("Kodi scan is running. Waiting...")
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():
log.info("Commit unsuccessful. Sync terminated.")
break
@ -206,9 +211,18 @@ class LibrarySync(threading.Thread):
# Abort was requested while waiting. We should exit
log.info("Commit unsuccessful.")
break
else:
count += 1
try:
connection.commit()
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):
# Only run once when first setting up. Can be run manually.