Timeout is passed into query runner

This commit is contained in:
Raul Ochoa 2016-10-10 12:00:54 +02:00
parent 51d4ff0698
commit 5401a7edff
2 changed files with 10 additions and 7 deletions

View File

@ -23,6 +23,10 @@ JobRunner.prototype.run = function (job_id, callback) {
} }
var query = job.getNextQuery(); var query = job.getNextQuery();
var timeout = 12 * 3600 * 1000;
if (Number.isFinite(global.settings.batch_query_timeout)) {
timeout = global.settings.batch_query_timeout;
}
try { try {
job.setStatus(jobStatus.RUNNING); job.setStatus(jobStatus.RUNNING);
@ -37,15 +41,15 @@ JobRunner.prototype.run = function (job_id, callback) {
profiler.done('running'); profiler.done('running');
self._run(job, query, profiler, callback); self._run(job, query, timeout, profiler, callback);
}); });
}); });
}; };
JobRunner.prototype._run = function (job, query, profiler, callback) { JobRunner.prototype._run = function (job, query, timeout, profiler, callback) {
var self = this; var self = this;
self.queryRunner.run(job.data.job_id, query, job.data.user, function (err /*, result */) { self.queryRunner.run(job.data.job_id, query, job.data.user, timeout, function (err /*, result */) {
if (err) { if (err) {
if (!err.code) { if (!err.code) {
return callback(err); return callback(err);

View File

@ -1,7 +1,6 @@
'use strict'; 'use strict';
var PSQL = require('cartodb-psql'); var PSQL = require('cartodb-psql');
var BATCH_QUERY_TIMEOUT = global.settings.batch_query_timeout || 12 * 3600 * 1000; // 12 hours in millisecond
var debug = require('./util/debug')('query-runner'); var debug = require('./util/debug')('query-runner');
function QueryRunner(userDatabaseMetadataService) { function QueryRunner(userDatabaseMetadataService) {
@ -10,7 +9,7 @@ function QueryRunner(userDatabaseMetadataService) {
module.exports = QueryRunner; module.exports = QueryRunner;
QueryRunner.prototype.run = function (job_id, sql, user, callback) { QueryRunner.prototype.run = function (job_id, sql, user, timeout, callback) {
this.userDatabaseMetadataService.getUserMetadata(user, function (err, userDatabaseMetadata) { this.userDatabaseMetadataService.getUserMetadata(user, function (err, userDatabaseMetadata) {
if (err) { if (err) {
return callback(err); return callback(err);
@ -18,7 +17,7 @@ QueryRunner.prototype.run = function (job_id, sql, user, callback) {
var pg = new PSQL(userDatabaseMetadata, {}, { destroyOnError: true }); var pg = new PSQL(userDatabaseMetadata, {}, { destroyOnError: true });
pg.query('SET statement_timeout=' + BATCH_QUERY_TIMEOUT, function (err) { pg.query('SET statement_timeout=' + timeout, function (err) {
if(err) { if(err) {
return callback(err); return callback(err);
} }
@ -26,7 +25,7 @@ QueryRunner.prototype.run = function (job_id, sql, user, callback) {
// mark query to allow to users cancel their queries // mark query to allow to users cancel their queries
sql = '/* ' + job_id + ' */ ' + sql; sql = '/* ' + job_id + ' */ ' + sql;
debug('Running query %s', sql); debug('Running query [timeout=%d] %s', timeout, sql);
pg.eventedQuery(sql, function (err, query) { pg.eventedQuery(sql, function (err, query) {
if (err) { if (err) {
return callback(err); return callback(err);