CartoDB-SQL-API/lib/monitoring/health-check.js

35 lines
744 B
JavaScript
Raw Normal View History

2018-10-24 21:42:33 +08:00
'use strict';
2019-12-24 01:19:08 +08:00
var step = require('step');
var fs = require('fs');
2014-08-27 00:40:58 +08:00
2019-12-24 01:19:08 +08:00
function HealthCheck (disableFile) {
this.disableFile = disableFile;
2014-08-27 00:40:58 +08:00
}
module.exports = HealthCheck;
2019-12-24 01:19:08 +08:00
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(
2019-12-24 01:19:08 +08:00
function getManualDisable () {
fs.readFile(self.disableFile, this);
},
2019-12-24 01:19:08 +08:00
function handleDisabledFile (err, data) {
var next = this;
if (err) {
return next();
}
if (data) {
err = new Error(data);
err.http_status = 503;
throw err;
}
},
2019-12-24 01:19:08 +08:00
function handleResult (err) {
callback(err);
2014-08-27 00:40:58 +08:00
}
);
};