Improve shutdown
This commit is contained in:
parent
1905a2bd28
commit
3ed4b142c0
15
app.js
15
app.js
@ -124,17 +124,26 @@ process.on('SIGHUP', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
process.on('SIGTERM', function () {
|
process.on('SIGTERM', function () {
|
||||||
server.batch.stop();
|
global.logger.debug('Signal TERM Received');
|
||||||
|
listener.close(function () {
|
||||||
|
global.logger.debug('Http server closed');
|
||||||
|
server.batch.stop(function (err) {
|
||||||
|
if (err) {
|
||||||
|
global.logger.error(err);
|
||||||
|
}
|
||||||
|
|
||||||
server.batch.drain(function (err) {
|
server.batch.drain(function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log('Exit with error');
|
global.logger.error(err);
|
||||||
return process.exit(1);
|
return process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Exit gracefully');
|
global.logger.info('Exit gracefully');
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
function isGteMinVersion(version, minVersion) {
|
function isGteMinVersion(version, minVersion) {
|
||||||
var versionMatch = /[a-z]?([0-9]*)/.exec(version);
|
var versionMatch = /[a-z]?([0-9]*)/.exec(version);
|
||||||
|
@ -152,6 +152,8 @@ Batch.prototype.drain = function (callback) {
|
|||||||
var workingUsers = this.getWorkInProgressUsers();
|
var workingUsers = this.getWorkInProgressUsers();
|
||||||
var batchQueues = queue(workingUsers.length);
|
var batchQueues = queue(workingUsers.length);
|
||||||
|
|
||||||
|
this.logger.debug('Drain batch-queries processing');
|
||||||
|
|
||||||
workingUsers.forEach(function (user) {
|
workingUsers.forEach(function (user) {
|
||||||
batchQueues.defer(self._drainJob.bind(self), user);
|
batchQueues.defer(self._drainJob.bind(self), user);
|
||||||
});
|
});
|
||||||
@ -197,6 +199,7 @@ Batch.prototype._drainJob = function (user, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Batch.prototype.stop = function (callback) {
|
Batch.prototype.stop = function (callback) {
|
||||||
|
this.logger.debug('Stop batch-queries processing');
|
||||||
this.removeAllListeners();
|
this.removeAllListeners();
|
||||||
this._stopScheduleInterval();
|
this._stopScheduleInterval();
|
||||||
this.jobSubscriber.unsubscribe(callback);
|
this.jobSubscriber.unsubscribe(callback);
|
||||||
|
Loading…
Reference in New Issue
Block a user