eslint errors

This commit is contained in:
Daniel García Aubert 2019-12-26 18:12:47 +01:00
parent fddc76b542
commit ac4d1c4e28
9 changed files with 27 additions and 21 deletions

View File

@ -42,7 +42,7 @@ Locker.prototype.unlock = function (resource, callback) {
Locker.prototype.startRenewal = function (resource) { Locker.prototype.startRenewal = function (resource) {
var self = this; var self = this;
if (!this.intervalIds.hasOwnProperty(resource)) { if (!Object.prototype.hasOwnProperty.call(this.intervalIds, resource)) {
this.intervalIds[resource] = setInterval(function () { this.intervalIds[resource] = setInterval(function () {
debug('Trying to extend lock resource=%s', resource); debug('Trying to extend lock resource=%s', resource);
self.locker.lock(resource, self.ttl, function (err, _lock) { self.locker.lock(resource, self.ttl, function (err, _lock) {
@ -59,7 +59,7 @@ Locker.prototype.startRenewal = function (resource) {
}; };
Locker.prototype.stopRenewal = function (resource) { Locker.prototype.stopRenewal = function (resource) {
if (this.intervalIds.hasOwnProperty(resource)) { if (Object.prototype.hasOwnProperty.call(this.intervalIds, resource)) {
clearInterval(this.intervalIds[resource]); clearInterval(this.intervalIds[resource]);
delete this.intervalIds[resource]; delete this.intervalIds[resource];
} }

View File

@ -72,7 +72,7 @@ RedisDistlockLocker.prototype.unlock = function (resource, callback) {
}; };
RedisDistlockLocker.prototype._getLock = function (resource) { RedisDistlockLocker.prototype._getLock = function (resource) {
if (this._locks.hasOwnProperty(resource)) { if (Object.prototype.hasOwnProperty.call(this._locks, resource)) {
return this._locks[resource]; return this._locks[resource];
} }
return null; return null;

View File

@ -27,6 +27,9 @@ module.exports = HostUserQueueMover;
HostUserQueueMover.prototype.moveOldJobs = function (callback) { HostUserQueueMover.prototype.moveOldJobs = function (callback) {
var self = this; var self = this;
this.getOldQueues(function (err, hosts) { this.getOldQueues(function (err, hosts) {
if (err) {
return callback(err);
}
var async = asyncQ(4); var async = asyncQ(4);
hosts.forEach(function (host) { hosts.forEach(function (host) {
async.defer(self.moveOldQueueJobs.bind(self), host); async.defer(self.moveOldQueueJobs.bind(self), host);
@ -78,6 +81,9 @@ HostUserQueueMover.prototype.processNextJob = function (host, callback) {
} }
client.lpop(QUEUE.OLD.PREFIX + host, function (err, jobId) { client.lpop(QUEUE.OLD.PREFIX + host, function (err, jobId) {
if (err) {
return callback(err);
}
self.pool.release(QUEUE.OLD.DB, client); self.pool.release(QUEUE.OLD.DB, client);
debug('Found jobId=%s at queue=%s', jobId, host); debug('Found jobId=%s at queue=%s', jobId, host);
if (!jobId) { if (!jobId) {

View File

@ -38,7 +38,7 @@ async function scan () {
const jobs = []; const jobs = [];
const initialCursor = '0'; const initialCursor = '0';
return await _scan(initialCursor, jobs); return _scan(initialCursor, jobs);
}; };
async function _scan (cursor, jobs) { async function _scan (cursor, jobs) {
@ -53,7 +53,7 @@ async function _scan (cursor, jobs) {
return jobs; return jobs;
} }
return await _scan(_cursor, jobs); return _scan(_cursor, jobs);
} }
async function getJob (key) { async function getJob (key) {

View File

@ -266,12 +266,12 @@ function parseQueryId (queryId) {
return null; return null;
} }
function elapsedTime (started_at, ended_at) { function elapsedTime (startedAt, endedAt) {
if (!started_at || !ended_at) { if (!startedAt || !endedAt) {
return; return;
} }
var start = new Date(started_at); var start = new Date(startedAt);
var end = new Date(ended_at); var end = new Date(endedAt);
return end.getTime() - start.getTime(); return end.getTime() - start.getTime();
} }

View File

@ -13,9 +13,9 @@ function hasDBParams (dbparams) {
return (dbparams.user && dbparams.host && dbparams.port && dbparams.dbname && dbparams.pass); return (dbparams.user && dbparams.host && dbparams.port && dbparams.dbname && dbparams.pass);
} }
QueryRunner.prototype.run = function (job_id, sql, user, timeout, dbparams, callback) { QueryRunner.prototype.run = function (jobId, sql, user, timeout, dbparams, callback) {
if (hasDBParams(dbparams)) { if (hasDBParams(dbparams)) {
return this._run(dbparams, job_id, sql, timeout, callback); return this._run(dbparams, jobId, sql, timeout, callback);
} }
const dbConfigurationError = new Error('Batch Job DB misconfiguration'); const dbConfigurationError = new Error('Batch Job DB misconfiguration');
@ -23,8 +23,8 @@ QueryRunner.prototype.run = function (job_id, sql, user, timeout, dbparams, call
return callback(dbConfigurationError); return callback(dbConfigurationError);
}; };
QueryRunner.prototype._run = function (dbparams, job_id, sql, timeout, callback) { QueryRunner.prototype._run = function (dbparams, jobId, sql, timeout, callback) {
var pg = new PSQL(dbparams); var pg = new PSQL(dbparams);
this.logger.debug('Running query [timeout=%d] %s', timeout, sql); this.logger.debug('Running query [timeout=%d] %s', timeout, sql);
pg.query(`/* ${job_id} */ ${sql}`, callback, false, timeout); pg.query(`/* ${jobId} */ ${sql}`, callback, false, timeout);
}; };

View File

@ -64,7 +64,7 @@ HostScheduler.prototype.lock = function (host, callback) {
return callback(err); return callback(err);
} }
if (!self.schedulers.hasOwnProperty(host)) { if (!Object.prototype.hasOwnProperty.call(self.schedulers, host)) {
var scheduler = new Scheduler(self.getCapacityProvider(host), self.taskRunner); var scheduler = new Scheduler(self.getCapacityProvider(host), self.taskRunner);
scheduler.on('done', self.unlock.bind(self, host)); scheduler.on('done', self.unlock.bind(self, host));
self.schedulers[host] = scheduler; self.schedulers[host] = scheduler;
@ -77,7 +77,7 @@ HostScheduler.prototype.lock = function (host, callback) {
HostScheduler.prototype.unlock = function (host) { HostScheduler.prototype.unlock = function (host) {
debug('[%s] unlock(%s)', this.name, host); debug('[%s] unlock(%s)', this.name, host);
if (this.schedulers.hasOwnProperty(host)) { if (Object.prototype.hasOwnProperty.call(this.schedulers, host)) {
// TODO stop scheduler? // TODO stop scheduler?
delete this.schedulers[host]; delete this.schedulers[host];
} }

View File

@ -77,7 +77,7 @@ Scheduler.prototype.schedule = function () {
forever( forever(
function (next) { function (next) {
debug('Waiting for task'); debug('Waiting for task');
self.acquire(function (err, taskEntity) { self.acquire(function (_err, taskEntity) {
debug('Acquired user=%j', taskEntity); debug('Acquired user=%j', taskEntity);
if (!taskEntity) { if (!taskEntity) {
@ -157,7 +157,7 @@ Scheduler.prototype.acquire = function (callback) {
}); });
}; };
Scheduler.prototype.release = function (err, taskEntity) { Scheduler.prototype.release = function (_err, taskEntity) {
debug('Released %j', taskEntity); debug('Released %j', taskEntity);
if (taskEntity.is(STATUS.PENDING)) { if (taskEntity.is(STATUS.PENDING)) {
this.tasksTree.insert(taskEntity); this.tasksTree.insert(taskEntity);

View File

@ -20,20 +20,20 @@ CartodbRequest.prototype.userByReq = function (req) {
return userByHostName(req.headers.host); return userByHostName(req.headers.host);
}; };
var re_userFromHost = new RegExp( var userFromHostRegex = new RegExp(
global.settings.user_from_host || '^([^\\.]+)\\.' // would extract "strk" from "strk.cartodb.com" global.settings.user_from_host || '^([^\\.]+)\\.' // would extract "strk" from "strk.cartodb.com"
); );
function userByHostName (host) { function userByHostName (host) {
var mat = host.match(re_userFromHost); var mat = host.match(userFromHostRegex);
if (!mat) { if (!mat) {
console.error("ERROR: user pattern '" + re_userFromHost + "' does not match hostname '" + host + "'"); console.error("ERROR: user pattern '" + userFromHostRegex + "' does not match hostname '" + host + "'");
return; return;
} }
if (mat.length !== 2) { if (mat.length !== 2) {
console.error( console.error(
"ERROR: pattern '" + re_userFromHost + "' gave unexpected matches against '" + host + "': " + mat "ERROR: pattern '" + userFromHostRegex + "' gave unexpected matches against '" + host + "': " + mat
); );
return; return;
} }