Eslint errors
This commit is contained in:
parent
ac4d1c4e28
commit
1e413a9332
@ -52,7 +52,7 @@ function queryParamsStrategy (input) {
|
|||||||
|
|
||||||
params.format = parseFormat(input.format);
|
params.format = parseFormat(input.format);
|
||||||
|
|
||||||
if (!formats.hasOwnProperty(params.format)) {
|
if (!Object.prototype.hasOwnProperty.call(formats, params.format)) {
|
||||||
throw new Error(`Invalid format: ${params.format}`);
|
throw new Error(`Invalid format: ${params.format}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = function socketTimeout () {
|
module.exports = function socketTimeout () {
|
||||||
if (!global.settings.hasOwnProperty('node_socket_timeout')) {
|
if (!Object.prototype.hasOwnProperty.call(global.settings, 'node_socket_timeout')) {
|
||||||
return function dummySocketTimeoutMiddleware (req, res, next) {
|
return function dummySocketTimeoutMiddleware (req, res, next) {
|
||||||
next();
|
next();
|
||||||
};
|
};
|
||||||
|
@ -73,9 +73,9 @@ function composeJobMiddlewares (metadataBackend, userDatabaseService, jobService
|
|||||||
|
|
||||||
function cancelJob (jobService) {
|
function cancelJob (jobService) {
|
||||||
return function cancelJobMiddleware (req, res, next) {
|
return function cancelJobMiddleware (req, res, next) {
|
||||||
const { job_id } = req.params;
|
const { job_id: jobId } = req.params;
|
||||||
|
|
||||||
jobService.cancel(job_id, (err, job) => {
|
jobService.cancel(jobId, (err, job) => {
|
||||||
if (req.profiler) {
|
if (req.profiler) {
|
||||||
req.profiler.done('cancelJob');
|
req.profiler.done('cancelJob');
|
||||||
}
|
}
|
||||||
@ -93,9 +93,9 @@ function cancelJob (jobService) {
|
|||||||
|
|
||||||
function getJob (jobService) {
|
function getJob (jobService) {
|
||||||
return function getJobMiddleware (req, res, next) {
|
return function getJobMiddleware (req, res, next) {
|
||||||
const { job_id } = req.params;
|
const { job_id: jobId } = req.params;
|
||||||
|
|
||||||
jobService.get(job_id, (err, job) => {
|
jobService.get(jobId, (err, job) => {
|
||||||
if (req.profiler) {
|
if (req.profiler) {
|
||||||
req.profiler.done('getJob');
|
req.profiler.done('getJob');
|
||||||
}
|
}
|
||||||
|
@ -18,9 +18,9 @@ var oAuth = (function () {
|
|||||||
// * in GET request
|
// * in GET request
|
||||||
// * in header
|
// * in header
|
||||||
me.parseTokens = function (req) {
|
me.parseTokens = function (req) {
|
||||||
var query_oauth = _.clone(req.method === 'POST' ? req.body : req.query);
|
var queryOauth = _.clone(req.method === 'POST' ? req.body : req.query);
|
||||||
var header_oauth = {};
|
var headerOauth = {};
|
||||||
var oauth_variables = ['oauth_body_hash',
|
var oauthVariables = ['oauth_body_hash',
|
||||||
'oauth_consumer_key',
|
'oauth_consumer_key',
|
||||||
'oauth_token',
|
'oauth_token',
|
||||||
'oauth_signature_method',
|
'oauth_signature_method',
|
||||||
@ -30,22 +30,22 @@ var oAuth = (function () {
|
|||||||
'oauth_version'];
|
'oauth_version'];
|
||||||
|
|
||||||
// pull only oauth tokens out of query
|
// pull only oauth tokens out of query
|
||||||
var non_oauth = _.difference(_.keys(query_oauth), oauth_variables);
|
var nonOauth = _.difference(_.keys(queryOauth), oauthVariables);
|
||||||
_.each(non_oauth, function (key) { delete query_oauth[key]; });
|
_.each(nonOauth, function (key) { delete queryOauth[key]; });
|
||||||
|
|
||||||
// pull oauth tokens out of header
|
// pull oauth tokens out of header
|
||||||
var header_string = req.headers.authorization;
|
var headerString = req.headers.authorization;
|
||||||
if (!_.isUndefined(header_string)) {
|
if (!_.isUndefined(headerString)) {
|
||||||
_.each(oauth_variables, function (oauth_key) {
|
_.each(oauthVariables, function (oauthKey) {
|
||||||
var matched_string = header_string.match(new RegExp(oauth_key + '=\"([^\"]+)\"'));
|
var matchedString = headerString.match(new RegExp(oauthKey + '="([^"]+)"'));
|
||||||
if (!_.isNull(matched_string)) {
|
if (!_.isNull(matchedString)) {
|
||||||
header_oauth[oauth_key] = decodeURIComponent(matched_string[1]);
|
headerOauth[oauthKey] = decodeURIComponent(matchedString[1]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// merge header and query oauth tokens. preference given to header oauth
|
// merge header and query oauth tokens. preference given to header oauth
|
||||||
return _.defaults(header_oauth, query_oauth);
|
return _.defaults(headerOauth, queryOauth);
|
||||||
};
|
};
|
||||||
|
|
||||||
// remove oauthy tokens from an object
|
// remove oauthy tokens from an object
|
||||||
@ -112,8 +112,8 @@ var oAuth = (function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var consumer = OAuthUtil.createConsumer(oAuthHash.consumer_key, oAuthHash.consumer_secret);
|
var consumer = OAuthUtil.createConsumer(oAuthHash.consumer_key, oAuthHash.consumer_secret);
|
||||||
var access_token = OAuthUtil.createToken(oAuthHash.access_token_token, oAuthHash.access_token_secret);
|
var accessToken = OAuthUtil.createToken(oAuthHash.access_token_token, oAuthHash.access_token_secret);
|
||||||
var signer = OAuthUtil.createHmac(consumer, access_token);
|
var signer = OAuthUtil.createHmac(consumer, accessToken);
|
||||||
|
|
||||||
var method = req.method;
|
var method = req.method;
|
||||||
var hostsToValidate = {};
|
var hostsToValidate = {};
|
||||||
@ -180,8 +180,8 @@ OAuthAuth.prototype.getCredentials = function () {
|
|||||||
|
|
||||||
OAuthAuth.prototype.hasCredentials = function () {
|
OAuthAuth.prototype.hasCredentials = function () {
|
||||||
if (this.isOAuthRequest === null) {
|
if (this.isOAuthRequest === null) {
|
||||||
var passed_tokens = oAuth.parseTokens(this.req);
|
var passedTokens = oAuth.parseTokens(this.req);
|
||||||
this.isOAuthRequest = !_.isEmpty(passed_tokens);
|
this.isOAuthRequest = !_.isEmpty(passedTokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.isOAuthRequest;
|
return this.isOAuthRequest;
|
||||||
|
@ -3,10 +3,6 @@
|
|||||||
const Logger = require('../services/logger');
|
const Logger = require('../services/logger');
|
||||||
|
|
||||||
class BatchLogger extends Logger {
|
class BatchLogger extends Logger {
|
||||||
constructor (path, name) {
|
|
||||||
super(path, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
log (job) {
|
log (job) {
|
||||||
return job.log(this.logger);
|
return job.log(this.logger);
|
||||||
}
|
}
|
||||||
|
@ -172,15 +172,15 @@ Batch.prototype.drain = function (callback) {
|
|||||||
|
|
||||||
Batch.prototype._drainJob = function (user, callback) {
|
Batch.prototype._drainJob = function (user, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var job_id = this.getWorkInProgressJob(user);
|
var jobId = this.getWorkInProgressJob(user);
|
||||||
|
|
||||||
if (!job_id) {
|
if (!jobId) {
|
||||||
return process.nextTick(function () {
|
return process.nextTick(function () {
|
||||||
return callback();
|
return callback();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.jobService.drain(job_id, function (err) {
|
this.jobService.drain(jobId, function (err) {
|
||||||
if (err && err.name === 'CancelNotAllowedError') {
|
if (err && err.name === 'CancelNotAllowedError') {
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
@ -189,12 +189,12 @@ Batch.prototype._drainJob = function (user, callback) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.clearWorkInProgressJob(user, job_id, function (err) {
|
self.clearWorkInProgressJob(user, jobId, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
self.logger.debug(new Error('Could not clear job from work-in-progress list. Reason: ' + err.message));
|
self.logger.debug(new Error('Could not clear job from work-in-progress list. Reason: ' + err.message));
|
||||||
}
|
}
|
||||||
|
|
||||||
self.jobQueue.enqueueFirst(user, job_id, callback);
|
self.jobQueue.enqueueFirst(user, jobId, callback);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -20,7 +20,7 @@ function toRedisParams (job) {
|
|||||||
delete obj.job_id;
|
delete obj.job_id;
|
||||||
|
|
||||||
for (var property in obj) {
|
for (var property in obj) {
|
||||||
if (obj.hasOwnProperty(property)) {
|
if (Object.prototype.hasOwnProperty.call(obj, property)) {
|
||||||
redisParams.push(property);
|
redisParams.push(property);
|
||||||
if (property === 'query' && typeof obj[property] !== 'string') {
|
if (property === 'query' && typeof obj[property] !== 'string') {
|
||||||
redisParams.push(JSON.stringify(obj[property]));
|
redisParams.push(JSON.stringify(obj[property]));
|
||||||
@ -33,7 +33,7 @@ function toRedisParams (job) {
|
|||||||
return redisParams;
|
return redisParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
function toObject (job_id, redisParams, redisValues) {
|
function toObject (jobId, redisParams, redisValues) {
|
||||||
var obj = {};
|
var obj = {};
|
||||||
|
|
||||||
redisParams.shift(); // job_id value
|
redisParams.shift(); // job_id value
|
||||||
@ -52,7 +52,7 @@ function toObject (job_id, redisParams, redisValues) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.job_id = job_id; // adds redisKey as object property
|
obj.job_id = jobId; // adds redisKey as object property
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
@ -61,20 +61,20 @@ function isJobFound (redisValues) {
|
|||||||
return !!(redisValues[0] && redisValues[1] && redisValues[2] && redisValues[3] && redisValues[4]);
|
return !!(redisValues[0] && redisValues[1] && redisValues[2] && redisValues[3] && redisValues[4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNotFoundError (job_id) {
|
function getNotFoundError (jobId) {
|
||||||
var notFoundError = new Error('Job with id ' + job_id + ' not found');
|
var notFoundError = new Error('Job with id ' + jobId + ' not found');
|
||||||
notFoundError.name = 'NotFoundError';
|
notFoundError.name = 'NotFoundError';
|
||||||
return notFoundError;
|
return notFoundError;
|
||||||
}
|
}
|
||||||
|
|
||||||
JobBackend.prototype.get = function (job_id, callback) {
|
JobBackend.prototype.get = function (jobId, callback) {
|
||||||
if (!job_id) {
|
if (!jobId) {
|
||||||
return callback(getNotFoundError(job_id));
|
return callback(getNotFoundError(jobId));
|
||||||
}
|
}
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
var redisParams = [
|
var redisParams = [
|
||||||
REDIS_PREFIX + job_id,
|
REDIS_PREFIX + jobId,
|
||||||
'user',
|
'user',
|
||||||
'status',
|
'status',
|
||||||
'query',
|
'query',
|
||||||
@ -96,10 +96,10 @@ JobBackend.prototype.get = function (job_id, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isJobFound(redisValues)) {
|
if (!isJobFound(redisValues)) {
|
||||||
return callback(getNotFoundError(job_id));
|
return callback(getNotFoundError(jobId));
|
||||||
}
|
}
|
||||||
|
|
||||||
var jobData = toObject(job_id, redisParams, redisValues);
|
var jobData = toObject(jobId, redisParams, redisValues);
|
||||||
|
|
||||||
callback(null, jobData);
|
callback(null, jobData);
|
||||||
});
|
});
|
||||||
|
@ -19,10 +19,10 @@ JobCanceller.prototype.cancel = function (job, callback) {
|
|||||||
doCancel(job.data.job_id, dbConfiguration, callback);
|
doCancel(job.data.job_id, dbConfiguration, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
function doCancel (job_id, dbConfiguration, callback) {
|
function doCancel (jobId, dbConfiguration, callback) {
|
||||||
var pg = new PSQL(dbConfiguration);
|
var pg = new PSQL(dbConfiguration);
|
||||||
|
|
||||||
getQueryPID(pg, job_id, function (err, pid) {
|
getQueryPID(pg, jobId, function (err, pid) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
@ -45,8 +45,8 @@ function doCancel (job_id, dbConfiguration, callback) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getQueryPID (pg, job_id, callback) {
|
function getQueryPID (pg, jobId, callback) {
|
||||||
var getPIDQuery = "SELECT pid FROM pg_stat_activity WHERE query LIKE '/* " + job_id + " */%'";
|
var getPIDQuery = "SELECT pid FROM pg_stat_activity WHERE query LIKE '/* " + jobId + " */%'";
|
||||||
|
|
||||||
pg.query(getPIDQuery, function (err, result) {
|
pg.query(getPIDQuery, function (err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -18,13 +18,13 @@ function JobRunner (jobService, jobQueue, queryRunner, metadataBackend, statsdCl
|
|||||||
this.statsdClient = statsdClient;
|
this.statsdClient = statsdClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
JobRunner.prototype.run = function (job_id, callback) {
|
JobRunner.prototype.run = function (jobId, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var profiler = new Profiler({ statsd_client: self.statsdClient });
|
var profiler = new Profiler({ statsd_client: self.statsdClient });
|
||||||
profiler.start('sqlapi.batch.job');
|
profiler.start('sqlapi.batch.job');
|
||||||
|
|
||||||
self.jobService.get(job_id, function (err, job) {
|
self.jobService.get(jobId, function (err, job) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
@ -70,6 +70,10 @@ JobRunner.prototype.getQueryStatementTimeout = function (username, callback) {
|
|||||||
|
|
||||||
var batchLimitsKey = REDIS_LIMITS.PREFIX + username;
|
var batchLimitsKey = REDIS_LIMITS.PREFIX + username;
|
||||||
this.metadataBackend.redisCmd(REDIS_LIMITS.DB, 'HGET', [batchLimitsKey, 'timeout'], function (err, timeoutLimit) {
|
this.metadataBackend.redisCmd(REDIS_LIMITS.DB, 'HGET', [batchLimitsKey, 'timeout'], function (err, timeoutLimit) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
if (timeoutLimit !== null && Number.isFinite(+timeoutLimit)) {
|
if (timeoutLimit !== null && Number.isFinite(+timeoutLimit)) {
|
||||||
timeout = +timeoutLimit;
|
timeout = +timeoutLimit;
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,8 @@ function JobService (jobBackend, jobCanceller, logger) {
|
|||||||
|
|
||||||
module.exports = JobService;
|
module.exports = JobService;
|
||||||
|
|
||||||
JobService.prototype.get = function (job_id, callback) {
|
JobService.prototype.get = function (jobId, callback) {
|
||||||
this.jobBackend.get(job_id, function (err, data) {
|
this.jobBackend.get(jobId, function (err, data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
@ -68,10 +68,10 @@ JobService.prototype.save = function (job, callback) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
JobService.prototype.cancel = function (job_id, callback) {
|
JobService.prototype.cancel = function (jobId, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
self.get(job_id, function (err, job) {
|
self.get(jobId, function (err, job) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
@ -98,17 +98,17 @@ JobService.prototype.cancel = function (job_id, callback) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
JobService.prototype.drain = function (job_id, callback) {
|
JobService.prototype.drain = function (jobId, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
self.get(job_id, function (err, job) {
|
self.get(jobId, function (err, job) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.jobCanceller.cancel(job, function (err) {
|
self.jobCanceller.cancel(job, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
self.logger.debug('There was an error while draining job %s, %s ', job_id, err);
|
self.logger.debug('There was an error while draining job %s, %s ', jobId, err);
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user