Close DB on shutdown
This commit is contained in:
1 parent
18a870f8c3
commit
1bd556fbb3
3 files changed
+17
-2
No files matched your search
@@ -90,7 +90,11 @@ class Core(Plugin):
|
|||||||
|
|
||||||
def shutdown():
|
def shutdown():
|
||||||
self.initShutdown()
|
self.initShutdown()
|
||||||
IOLoop.current().add_callback(shutdown)
|
|
||||||
|
if IOLoop.current()._closing:
|
||||||
|
shutdown()
|
||||||
|
else:
|
||||||
|
IOLoop.current().add_callback(shutdown)
|
||||||
|
|
||||||
return 'shutdown'
|
return 'shutdown'
|
||||||
|
|
||||||
@@ -139,7 +143,8 @@ class Core(Plugin):
|
|||||||
log.debug('Safe to shutdown/restart')
|
log.debug('Safe to shutdown/restart')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
IOLoop.current().stop()
|
if not IOLoop.current()._closing:
|
||||||
|
IOLoop.current().stop()
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
pass
|
pass
|
||||||
except:
|
except:
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ class Database(object):
|
|||||||
|
|
||||||
addEvent('database.setup_index', self.setupIndex)
|
addEvent('database.setup_index', self.setupIndex)
|
||||||
addEvent('app.migrate', self.migrate)
|
addEvent('app.migrate', self.migrate)
|
||||||
|
addEvent('app.after_shutdown', self.close)
|
||||||
|
|
||||||
def getDB(self):
|
def getDB(self):
|
||||||
|
|
||||||
@@ -37,6 +38,9 @@ class Database(object):
|
|||||||
|
|
||||||
return self.db
|
return self.db
|
||||||
|
|
||||||
|
def close(self, **kwargs):
|
||||||
|
self.getDB().close()
|
||||||
|
|
||||||
def setupIndex(self, index_name, klass):
|
def setupIndex(self, index_name, klass):
|
||||||
|
|
||||||
self.indexes.append(index_name)
|
self.indexes.append(index_name)
|
||||||
|
|||||||
@@ -262,8 +262,14 @@ def runCouchPotato(options, base_path, args, data_dir = None, log_dir = None, En
|
|||||||
|
|
||||||
# Go go go!
|
# Go go go!
|
||||||
from tornado.ioloop import IOLoop
|
from tornado.ioloop import IOLoop
|
||||||
|
from tornado.autoreload import add_reload_hook
|
||||||
loop = IOLoop.current()
|
loop = IOLoop.current()
|
||||||
|
|
||||||
|
# Reload hook
|
||||||
|
def test():
|
||||||
|
fireEvent('app.shutdown')
|
||||||
|
add_reload_hook(test)
|
||||||
|
|
||||||
# Some logging and fire load event
|
# Some logging and fire load event
|
||||||
try: log.info('Starting server on port %(port)s', config)
|
try: log.info('Starting server on port %(port)s', config)
|
||||||
except: pass
|
except: pass
|
||||||
|
|||||||
Reference in new issue
Block a user