Now batch service is linked to express app in order to make it accesible from main app module to expose drain mechanism
This commit is contained in:
parent
1e49fbc33d
commit
e9bd93cf3f
13
app.js
13
app.js
@ -97,3 +97,16 @@ process.on('SIGHUP', function() {
|
||||
console.log('Log files reloaded');
|
||||
});
|
||||
});
|
||||
|
||||
process.on('SIGTERM', function () {
|
||||
app.batch.stop();
|
||||
app.batch.drain(function (err) {
|
||||
if (err) {
|
||||
console.log('Exit with error');
|
||||
return process.exit(1);
|
||||
}
|
||||
|
||||
console.log('Exit gracefully');
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
|
@ -39,7 +39,7 @@ var CacheStatusController = require('./controllers/cache_status_controller');
|
||||
var HealthCheckController = require('./controllers/health_check_controller');
|
||||
var VersionController = require('./controllers/version_controller');
|
||||
|
||||
var batch = require('../batch');
|
||||
var batchFactory = require('../batch');
|
||||
|
||||
process.env.PGAPPNAME = process.env.PGAPPNAME || 'cartodb_sqlapi';
|
||||
|
||||
@ -206,7 +206,8 @@ function App() {
|
||||
var isBatchProcess = process.argv.indexOf('--no-batch') === -1;
|
||||
|
||||
if (global.settings.environment !== 'test' && isBatchProcess) {
|
||||
batch(metadataBackend).start();
|
||||
app.batch = batchFactory(metadataBackend);
|
||||
app.batch.start();
|
||||
}
|
||||
|
||||
return app;
|
||||
|
@ -15,21 +15,7 @@ function Batch(jobSubscriber, jobQueuePool, jobRunner, jobCanceller) {
|
||||
util.inherits(Batch, EventEmitter);
|
||||
|
||||
Batch.prototype.start = function () {
|
||||
var self = this;
|
||||
this._subscribe();
|
||||
|
||||
process.on('SIGTERM', function () {
|
||||
self.stop();
|
||||
self.drain(function (err) {
|
||||
if (err) {
|
||||
console.log('Exit with error');
|
||||
return process.exit(1);
|
||||
}
|
||||
|
||||
console.log('Exit gracefully');
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Batch.prototype._subscribe = function () {
|
||||
|
Loading…
Reference in New Issue
Block a user