CartoDB-SQL-API/app/monitoring/health_check.js

35 lines
713 B
JavaScript
Raw Normal View History

2018-10-24 21:42:33 +08:00
'use strict';
2015-05-13 00:02:23 +08:00
var step = require('step'),
fs = require('fs');
2014-08-27 00:40:58 +08:00
function HealthCheck(disableFile) {
this.disableFile = disableFile;
2014-08-27 00:40:58 +08:00
}
module.exports = HealthCheck;
HealthCheck.prototype.check = function(callback) {
var self = this;
2014-08-27 00:40:58 +08:00
2015-05-13 00:02:23 +08:00
step(
function getManualDisable() {
fs.readFile(self.disableFile, this);
},
function handleDisabledFile(err, data) {
var next = this;
if (err) {
return next();
}
if (!!data) {
err = new Error(data);
err.http_status = 503;
throw err;
}
},
2015-04-06 22:08:29 +08:00
function handleResult(err) {
callback(err);
2014-08-27 00:40:58 +08:00
}
);
};