CartoDB-SQL-API/batch/query_runner.js
Raúl Marín df523960a2
Fix test timeouts (#612)
* Tests: Work with re-runs

* Test: Adapt copyfrom test
- Reduce timeout from 10 to 1 ms.
- Increase the size of the file from 6 to 2016 rows.

* Use node-cartodb-psql 0.14.0

Ref: https://github.com/CartoDB/CartoDB-SQL-API/pull/612
2019-09-13 11:28:37 +02:00

31 lines
951 B
JavaScript

'use strict';
var PSQL = require('cartodb-psql');
function QueryRunner(userDatabaseMetadataService, logger) {
this.userDatabaseMetadataService = userDatabaseMetadataService;
this.logger = logger;
}
module.exports = QueryRunner;
function hasDBParams (dbparams) {
return (dbparams.user && dbparams.host && dbparams.port && dbparams.dbname && dbparams.pass);
}
QueryRunner.prototype.run = function (job_id, sql, user, timeout, dbparams, callback) {
if (hasDBParams(dbparams)) {
return this._run(dbparams, job_id, sql, timeout, callback);
}
const dbConfigurationError = new Error('Batch Job DB misconfiguration');
return callback(dbConfigurationError);
};
QueryRunner.prototype._run = function (dbparams, job_id, sql, timeout, callback) {
var pg = new PSQL(dbparams);
this.logger.debug('Running query [timeout=%d] %s', timeout, sql);
pg.query(`/* ${job_id} */ ${sql}`, callback, false, timeout);
};