Merge pull request #131 from mozilla/heartbeat

added __heartbeat__
This commit is contained in:
Danny Coates 2017-06-23 12:15:25 -07:00 committed by GitHub
commit e4fafc7472
2 changed files with 31 additions and 8 deletions

View file

@ -21,10 +21,13 @@ const log = mozlog('portal.server');
const app = express();
app.engine('handlebars', exphbs({
app.engine(
'handlebars',
exphbs({
defaultLayout: 'main',
partialsDir: 'views/partials/'
}));
})
);
app.set('view engine', 'handlebars');
app.use(helmet());
@ -32,7 +35,6 @@ app.use(busboy());
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, '../public')));
app.get('/', (req, res) => {
res.render('index', {
shouldRenderAnalytics: notLocalHost,
@ -155,6 +157,10 @@ app.get('/__lbheartbeat__', (req, res) => {
res.sendStatus(200);
});
app.get('/__heartbeat__', (req, res) => {
storage.ping().then(() => res.sendStatus(200), () => res.sendStatus(500));
});
app.listen(conf.listen_port, () => {
log.info('startServer:', `Portal app listening on port ${conf.listen_port}!`);
});

View file

@ -14,7 +14,8 @@ const log = mozlog('portal.storage');
const redis = require('redis');
const redis_client = redis.createClient({
host: conf.redis_host
host: conf.redis_host,
connect_timeout: 10000
});
redis_client.on('error', err => {
@ -29,7 +30,8 @@ if (notLocalHost) {
get: awsGet,
set: awsSet,
delete: awsDelete,
forceDelete: awsForceDelete
forceDelete: awsForceDelete,
ping: awsPing
};
} else {
module.exports = {
@ -39,7 +41,8 @@ if (notLocalHost) {
get: localGet,
set: localSet,
delete: localDelete,
forceDelete: localForceDelete
forceDelete: localForceDelete,
ping: localPing
};
}
@ -124,6 +127,14 @@ function localForceDelete(id) {
});
}
function localPing() {
return new Promise((resolve, reject) => {
redis_client.ping(err => {
return err ? reject() : resolve();
});
});
}
function awsLength(id) {
const params = {
Bucket: conf.s3_bucket,
@ -215,3 +226,9 @@ function awsForceDelete(id) {
});
});
}
function awsPing() {
return localPing().then(() =>
s3.headBucket({ Bucket: conf.s3_bucket }).promise()
);
}