2015-09-04 22:22:02 +02:00
|
|
|
import sqlite3
|
|
|
|
from twisted.internet import task, reactor
|
|
|
|
import logging
|
|
|
|
|
|
|
|
|
2015-09-08 21:42:56 +02:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2015-09-04 22:22:02 +02:00
|
|
|
def rerun_if_locked(f):
|
|
|
|
|
|
|
|
def rerun(err, *args, **kwargs):
|
|
|
|
if err.check(sqlite3.OperationalError) and err.value.message == "database is locked":
|
2015-09-08 21:42:56 +02:00
|
|
|
log.warning("database was locked. rerunning %s with args %s, kwargs %s",
|
|
|
|
str(f), str(args), str(kwargs))
|
2015-09-04 22:22:02 +02:00
|
|
|
return task.deferLater(reactor, 0, wrapper, *args, **kwargs)
|
|
|
|
return err
|
|
|
|
|
|
|
|
def wrapper(*args, **kwargs):
|
|
|
|
d = f(*args, **kwargs)
|
|
|
|
d.addErrback(rerun, *args, **kwargs)
|
|
|
|
return d
|
|
|
|
|
|
|
|
return wrapper
|