Don't close idle db connection during rebuild
This commit is contained in:
parent
da9af181dd
commit
8cf30893f2
2 changed files with 7 additions and 6 deletions
|
@ -21,7 +21,7 @@ def dbCleanup():
|
||||||
time.sleep(60 * 5)
|
time.sleep(60 * 5)
|
||||||
for db in opened_dbs[:]:
|
for db in opened_dbs[:]:
|
||||||
idle = time.time() - db.last_query_time
|
idle = time.time() - db.last_query_time
|
||||||
if idle > 60 * 5:
|
if idle > 60 * 5 and db.close_idle:
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
gevent.spawn(dbCleanup)
|
gevent.spawn(dbCleanup)
|
||||||
|
@ -29,7 +29,7 @@ gevent.spawn(dbCleanup)
|
||||||
|
|
||||||
class Db(object):
|
class Db(object):
|
||||||
|
|
||||||
def __init__(self, schema, db_path):
|
def __init__(self, schema, db_path, close_idle=False):
|
||||||
self.db_path = db_path
|
self.db_path = db_path
|
||||||
self.db_dir = os.path.dirname(db_path) + "/"
|
self.db_dir = os.path.dirname(db_path) + "/"
|
||||||
self.schema = schema
|
self.schema = schema
|
||||||
|
@ -44,10 +44,11 @@ class Db(object):
|
||||||
self.db_keyvalues = {}
|
self.db_keyvalues = {}
|
||||||
self.delayed_queue = []
|
self.delayed_queue = []
|
||||||
self.delayed_queue_thread = None
|
self.delayed_queue_thread = None
|
||||||
|
self.close_idle = close_idle
|
||||||
self.last_query_time = time.time()
|
self.last_query_time = time.time()
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<Db#%s:%s>" % (id(self), self.db_path)
|
return "<Db#%s:%s close_idle:%s>" % (id(self), self.db_path, self.close_idle)
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
if self not in opened_dbs:
|
if self not in opened_dbs:
|
||||||
|
|
|
@ -45,10 +45,10 @@ class SiteStorage(object):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Create new databaseobject with the site's schema
|
# Create new databaseobject with the site's schema
|
||||||
def openDb(self):
|
def openDb(self, close_idle=False):
|
||||||
schema = self.getDbSchema()
|
schema = self.getDbSchema()
|
||||||
db_path = self.getPath(schema["db_file"])
|
db_path = self.getPath(schema["db_file"])
|
||||||
return Db(schema, db_path)
|
return Db(schema, db_path, close_idle=close_idle)
|
||||||
|
|
||||||
def closeDb(self):
|
def closeDb(self):
|
||||||
if self.db:
|
if self.db:
|
||||||
|
@ -77,7 +77,7 @@ class SiteStorage(object):
|
||||||
|
|
||||||
if self.db:
|
if self.db:
|
||||||
self.db.close()
|
self.db.close()
|
||||||
self.db = self.openDb()
|
self.db = self.openDb(close_idle=True)
|
||||||
|
|
||||||
changed_tables = self.db.checkTables()
|
changed_tables = self.db.checkTables()
|
||||||
if changed_tables:
|
if changed_tables:
|
||||||
|
|
Loading…
Reference in a new issue