added __heartbeat__

This commit is contained in:
Danny Coates 2017-06-23 11:14:33 -07:00
parent 2691dfcf2f
commit d247e0ba31
No known key found for this signature in database
GPG Key ID: 4C442633C62E00CB
2 changed files with 31 additions and 8 deletions

View File

@ -16,10 +16,13 @@ const log = mozlog('portal.server');
const app = express(); const app = express();
app.engine('handlebars', exphbs({ app.engine(
defaultLayout: 'main', 'handlebars',
partialsDir: 'views/partials/' exphbs({
})); defaultLayout: 'main',
partialsDir: 'views/partials/'
})
);
app.set('view engine', 'handlebars'); app.set('view engine', 'handlebars');
app.use(helmet()); app.use(helmet());
@ -27,7 +30,6 @@ app.use(busboy());
app.use(bodyParser.json()); app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, '../public'))); app.use(express.static(path.join(__dirname, '../public')));
app.get('/', (req, res) => { app.get('/', (req, res) => {
res.render('index', { res.render('index', {
shouldRenderAnalytics: notLocalHost, shouldRenderAnalytics: notLocalHost,
@ -150,6 +152,10 @@ app.get('/__lbheartbeat__', (req, res) => {
res.sendStatus(200); res.sendStatus(200);
}); });
app.get('/__heartbeat__', (req, res) => {
storage.ping().then(() => res.sendStatus(200), () => res.sendStatus(500));
});
app.listen(conf.listen_port, () => { app.listen(conf.listen_port, () => {
log.info('startServer:', `Portal app listening on port ${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 = require('redis');
const redis_client = redis.createClient({ const redis_client = redis.createClient({
host: conf.redis_host host: conf.redis_host,
connect_timeout: 10000
}); });
redis_client.on('error', err => { redis_client.on('error', err => {
@ -29,7 +30,8 @@ if (notLocalHost) {
get: awsGet, get: awsGet,
set: awsSet, set: awsSet,
delete: awsDelete, delete: awsDelete,
forceDelete: awsForceDelete forceDelete: awsForceDelete,
ping: awsPing
}; };
} else { } else {
module.exports = { module.exports = {
@ -39,7 +41,8 @@ if (notLocalHost) {
get: localGet, get: localGet,
set: localSet, set: localSet,
delete: localDelete, delete: localDelete,
forceDelete: localForceDelete forceDelete: localForceDelete,
ping: localPing
}; };
} }
@ -120,6 +123,14 @@ function localForceDelete(id) {
}); });
} }
function localPing() {
return new Promise((resolve, reject) => {
redis_client.ping(err => {
return err ? reject() : resolve();
});
});
}
function awsLength(id) { function awsLength(id) {
const params = { const params = {
Bucket: conf.s3_bucket, Bucket: conf.s3_bucket,
@ -211,3 +222,9 @@ function awsForceDelete(id) {
}); });
}); });
} }
function awsPing() {
return localPing().then(() =>
s3.headBucket({ Bucket: conf.s3_bucket }).promise()
);
}