Process exit when Redis connection failed

This commit is contained in:
Aurélien Georget 2017-02-14 14:34:01 +01:00
parent eade0d37c7
commit 0a2db78275
3 changed files with 19 additions and 10 deletions

View File

@ -90,7 +90,7 @@ module.exports = function (strapi) {
// Return callback if there is no model
if (_.isEmpty(models)) {
cb();
// Break the loop.
return false;
}

View File

@ -15,7 +15,7 @@ const Redis = require('ioredis');
* Redis hook
*/
module.exports = function () {
module.exports = function (strapi) {
const hook = {
/**
@ -26,7 +26,8 @@ module.exports = function () {
port: 6379,
host: 'localhost',
family: 4,
db: 0
db: 0,
showFriendlyErrorStack: (process.env.NODE_ENV !== 'production')
},
/**
@ -49,9 +50,9 @@ module.exports = function () {
const redis = new Redis(connection.settings);
redis.on('error', (err) => {
cb(err);
return process.kill();
strapi.log.error(err);
process.exit(0);
return;
});
// Utils function.
@ -93,7 +94,9 @@ module.exports = function () {
});
}
done();
redis.on('ready', () => {
done();
});
} catch (e) {
cb(e);

View File

@ -43,7 +43,7 @@ module.exports = function () {
watch: true,
watchDirectory: process.cwd(),
watchIgnoreDotFiles: true, // Whether to ignore file starting with a '.'
watchIgnorePatterns: ['node_modules/**/*', 'public/**/*'], // Ignore patterns to use when watching files.
watchIgnorePatterns: ['node_modules/**/*', 'public/**/*', '.git/**/*', '.idea'], // Ignore patterns to use when watching files.
killTree: true, // Kills the entire child process tree on `exit`,
spinSleepTime: 0,
command: 'node --harmony-async-await'
@ -52,9 +52,15 @@ module.exports = function () {
const child = new (forever.Monitor)('server.js', options);
// Run listeners
child.on('restart', () => {
child.on('watch:restart', (info) => {
console.log();
logger.info('Restarting due to changes...');
logger.verbose('Restarting due to ' + info.file + '... (' + info.stat.replace(child.cwd, '.') + ')');
console.log();
});
child.on('exit:code', function(code) {
console.log();
process.exit(code);
});
// Start child process