Skip to content

Commit

Permalink
[feature] Check database row with saving status on "shutdown"
Browse files Browse the repository at this point in the history
  • Loading branch information
konovalovsergey committed Sep 3, 2024
1 parent 2cb1493 commit 5a68653
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
16 changes: 16 additions & 0 deletions DocService/sources/databaseConnectors/baseConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,21 @@ function getExpired(ctx, maxCount, expireSeconds) {
}, false, false, values);
});
}
function getCountWithStatus(ctx, status) {
return new Promise(function(resolve, reject) {
const values = [];
const sqlParam = addSqlParameter(status, values);
const sqlCommand = `SELECT COUNT(id) AS count FROM ${cfgTableResult} WHERE status=${sqlParam};`;
dbInstance.sqlQuery(ctx, sqlCommand, function(error, result) {
if (error) {
reject(error);
} else {
let res = Number(result[0].count)
resolve(!isNaN(res) ? res : 0);
}
}, false, false, values);
});
}

function isLockCriticalSection(id) {
return !!(g_oCriticalSection[id]);
Expand Down Expand Up @@ -373,6 +388,7 @@ module.exports = {
isLockCriticalSection,
getDocumentsWithChanges,
getExpired,
getCountWithStatus,
healthCheck,
getEmptyCallbacks,
getTableColumns,
Expand Down
6 changes: 4 additions & 2 deletions DocService/sources/shutdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var configCoAuthoring = config.get('services.CoAuthoring');
var co = require('co');
var logger = require('./../../Common/sources/logger');
var pubsubService = require('./pubsubRabbitMQ');
const sqlBase = require('./databaseConnectors/baseConnector');
var commonDefines = require('./../../Common/sources/commondefines');
var constants = require('./../../Common/sources/constants');
var utils = require('./../../Common/sources/utils');
Expand Down Expand Up @@ -77,8 +78,9 @@ exports.shutdown = function(ctx, editorStat, status) {
break;
}
var remainingFiles = yield editorStat.getShutdownCount(redisKeyShutdown);
ctx.logger.debug('shutdown remaining files:%d', remainingFiles);
if (!isStartWait && remainingFiles <= 0) {
let inSavingStatus = yield sqlBase.getCountWithStatus(ctx, commonDefines.FileStatus.SaveVersion);
ctx.logger.debug('shutdown remaining files editorStat:%d, db:%d', remainingFiles, inSavingStatus);
if (!isStartWait && (remainingFiles + inSavingStatus) <= 0) {
break;
}
yield utils.sleep(LOOP_TIMEOUT);
Expand Down

0 comments on commit 5a68653

Please sign in to comment.