Windshaft-cartodb/lib/backends/analysis-status.js

39 lines
968 B
JavaScript
Raw Normal View History

'use strict';
var PSQL = require('cartodb-psql');
2019-10-22 01:07:24 +08:00
function AnalysisStatusBackend () {
}
module.exports = AnalysisStatusBackend;
AnalysisStatusBackend.prototype.getNodeStatus = function (nodeId, dbParams, callback) {
var statusQuery = [
'SELECT node_id, status, updated_at, last_error_message as error_message',
2019-12-02 20:43:19 +08:00
'FROM cartodb.cdb_analysis_catalog where node_id = \'' + nodeId + '\''
].join(' ');
var pg = new PSQL(dbParams);
2019-10-22 01:07:24 +08:00
pg.query(statusQuery, function (err, result) {
if (err) {
return callback(err, result);
}
result = result || {};
var rows = result.rows || [];
var statusResponse = rows[0] || {
node_id: nodeId,
status: 'unknown'
};
if (statusResponse.status !== 'failed') {
delete statusResponse.error_message;
}
return callback(null, statusResponse);
}, true); // use read-only transaction
};