summaryrefslogtreecommitdiff
path: root/app.js
diff options
context:
space:
mode:
authorCheng-Han, Wu2016-06-17 16:09:33 +0800
committerCheng-Han, Wu2016-06-17 16:09:33 +0800
commitdbc126b156f301c18d3963cd269dcd1eac040873 (patch)
tree0032b539ed308d3972e209fd3752011e0ac673ef /app.js
parent56b4739e6d2f455f7b9a40f8c54b3f543bef1790 (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.js33
1 files changed, 20 insertions, 13 deletions
diff --git a/app.js b/app.js
index 58578644..31bf8680 100644
--- a/app.js
+++ b/app.js
@@ -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