2016-04-14 16:59:51 +08:00
|
|
|
var PSQL = require('cartodb-psql');
|
|
|
|
|
2016-04-14 19:25:56 +08:00
|
|
|
function AnalysisStatusBackend() {
|
2016-04-14 16:59:51 +08:00
|
|
|
}
|
|
|
|
|
2016-04-14 19:25:56 +08:00
|
|
|
module.exports = AnalysisStatusBackend;
|
2016-04-14 16:59:51 +08:00
|
|
|
|
2018-03-22 19:30:51 +08:00
|
|
|
AnalysisStatusBackend.prototype.getNodeStatus = function (nodeId, dbParams, callback) {
|
2016-07-05 00:40:11 +08:00
|
|
|
var statusQuery = [
|
|
|
|
'SELECT node_id, status, updated_at, last_error_message as error_message',
|
|
|
|
'FROM cdb_analysis_catalog where node_id = \'' + nodeId + '\''
|
|
|
|
].join(' ');
|
2016-04-14 16:59:51 +08:00
|
|
|
|
2018-03-22 19:30:51 +08:00
|
|
|
var pg = new PSQL(dbParams);
|
|
|
|
|
2016-04-14 16:59:51 +08:00
|
|
|
pg.query(statusQuery, function(err, result) {
|
|
|
|
if (err) {
|
|
|
|
return callback(err, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
result = result || {};
|
|
|
|
|
|
|
|
var rows = result.rows || [];
|
|
|
|
|
2016-07-05 00:40:11 +08:00
|
|
|
var statusResponse = rows[0] || {
|
2016-04-14 16:59:51 +08:00
|
|
|
node_id: nodeId,
|
|
|
|
status: 'unknown'
|
2016-07-05 00:40:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
if (statusResponse.status !== 'failed') {
|
|
|
|
delete statusResponse.error_message;
|
|
|
|
}
|
|
|
|
|
|
|
|
return callback(null, statusResponse);
|
2016-04-14 16:59:51 +08:00
|
|
|
}, true); // use read-only transaction
|
|
|
|
};
|