diff options
author | Cheng-Han, Wu | 2016-06-17 16:09:33 +0800 |
---|---|---|
committer | Cheng-Han, Wu | 2016-06-17 16:09:33 +0800 |
commit | dbc126b156f301c18d3963cd269dcd1eac040873 (patch) | |
tree | 0032b539ed308d3972e209fd3752011e0ac673ef /app.js | |
parent | 56b4739e6d2f455f7b9a40f8c54b3f543bef1790 (diff) |
Add support of saving note revision and improve app start and stop procedure to ensure data integrity
Diffstat (limited to 'app.js')
-rw-r--r-- | app.js | 33 |
1 files changed, 20 insertions, 13 deletions
@@ -484,16 +484,26 @@ function startListen() { if (config.usessl) { server.listen(config.port, function () { logger.info('HTTPS Server listening at port %d', config.port); + config.maintenance = false; }); } else { server.listen(config.port, function () { logger.info('HTTP Server listening at port %d', config.port); + config.maintenance = false; }); } } // sync db then start listen -models.sequelize.sync().then(startListen); +models.sequelize.sync().then(function () { + // check if realtime is ready + if (realtime.isReady()) { + models.Revision.checkAllNotesRevision(function (err, notes) { + if (err) return new Error(err); + if (notes.length <= 0) return startListen(); + }); + } +}); // log uncaught exception process.on('uncaughtException', function (err) { @@ -510,21 +520,18 @@ process.on('SIGINT', function () { Object.keys(io.sockets.sockets).forEach(function (key) { var socket = io.sockets.sockets[key]; // notify client server going into maintenance status - socket.emit('maintenance', config.version); + socket.emit('maintenance'); socket.disconnect(true); }); var checkCleanTimer = setInterval(function () { - var usersCount = Object.keys(realtime.users).length; - var notesCount = Object.keys(realtime.notes).length; - // check if all users and notes array are empty - if (usersCount == 0 && notesCount == 0) { - // close db connection - models.sequelize.close(); - clearInterval(checkCleanTimer); - // wait for a while before exit - setTimeout(function () { - process.exit(0); - }, 100); + if (realtime.isReady()) { + models.Revision.checkAllNotesRevision(function (err, notes) { + if (err) return new Error(err); + if (notes.length <= 0) { + clearInterval(checkCleanTimer); + return process.exit(0); + } + }); } }, 100); });
\ No newline at end of file |