fix: keep wait_ready to his initial state on pm2 reload all #4069

This commit is contained in:
Unitech 2018-12-19 15:59:52 +01:00
parent f0c465db55
commit bb1918971b
5 changed files with 51 additions and 10 deletions

View File

@ -1085,6 +1085,10 @@ class API {
// Is KM linked?
resolved_paths.km_link = that.gl_is_km_linked;
if (resolved_paths.wait_ready) {
Common.warn(`App ${resolved_paths.name} has option 'wait_ready' set, waiting for app to be ready...`)
}
that.Client.executeRemote('prepare', resolved_paths, function(err, data) {
if (err) {
Common.printError(conf.PREFIX_MSG_ERR + 'Process failed to launch %s', err.message ? err.message : err);

View File

@ -465,6 +465,11 @@ Common.log = function(msg) {
return console.log(`${cst.PREFIX_MSG}${msg}`);
}
Common.warn = function(msg) {
if (process.env.PM2_SILENT || process.env.PM2_PROGRAMMATIC === 'true') return false;
return console.log(`${cst.PREFIX_MSG_WARNING}${msg}`);
}
Common.logMod = function(msg) {
if (process.env.PM2_SILENT || process.env.PM2_PROGRAMMATIC === 'true') return false;
return console.log(`${cst.PREFIX_MSG_MOD}${msg}`);

View File

@ -122,8 +122,6 @@ function hardReload(God, id, wait_msg, cb) {
old_worker.pm2_env.pm_id = t_key;
old_worker.pm_id = t_key;
new_env.wait_ready = false;
God.executeApp(new_env, function(err, new_worker) {
if (err) return cb(err);

View File

@ -10,7 +10,7 @@ var server = http.createServer(function(req, res) {
// 1# Notify application ready
setTimeout(function() {
process.send('ready');
}, 2000);
}, 1000);
});

View File

@ -19,8 +19,10 @@ describe('Wait ready / Graceful start / restart', function() {
cwd : '../fixtures/listen-timeout/'
});
after(function(done) {
pm2.kill(done)
before(function(done) {
pm2.delete('all', function() {
done()
});
});
describe('(FORK) Listen timeout feature', function() {
@ -49,7 +51,7 @@ describe('Wait ready / Graceful start / restart', function() {
should(apps[0].pm2_env.status).eql('online');
done();
})
}, 3000);
}, 1500);
});
it('should have listen timeout updated', function(done) {
@ -61,7 +63,7 @@ describe('Wait ready / Graceful start / restart', function() {
it('should take listen timeout into account', function(done) {
var called = false;
var plan = new Plan(3, done);
var plan = new Plan(4, done);
setTimeout(function() {
should(called).be.false();
@ -71,6 +73,11 @@ describe('Wait ready / Graceful start / restart', function() {
setTimeout(function() {
should(called).be.true();
plan.ok(true);
pm2.list((err, apps) => {
should(apps[0].pm2_env.wait_ready).eql(true)
plan.ok(true)
})
}, 1500);
pm2.reload('all', function(err, data) {
@ -123,15 +130,16 @@ describe('Wait ready / Graceful start / restart', function() {
script : './wait-ready.js',
listen_timeout : 1000,
wait_ready : true,
instances : 2,
name : 'echo'
instances : 1,
exec_mode: 'cluster',
name : 'http'
});
setTimeout(function() {
pm2.list(function(err, apps) {
should(apps[0].pm2_env.status).eql('launching');
});
}, 800);
}, 500);
setTimeout(function() {
pm2.list(function(err, apps) {
@ -140,6 +148,32 @@ describe('Wait ready / Graceful start / restart', function() {
})
}, 1500);
});
it('should take listen timeout into account', function(done) {
var called = false;
var plan = new Plan(4, done);
setTimeout(function() {
should(called).be.false();
plan.ok(true);
}, 500);
setTimeout(function() {
should(called).be.true();
plan.ok(true);
pm2.list((err, apps) => {
should(apps[0].pm2_env.wait_ready).eql(true)
plan.ok(true)
})
}, 1500);
pm2.reload('all', function(err, data) {
called = true;
plan.ok(true);
});
});
});
});