CartoDB-SQL-API/batch/job_counter.js
2015-12-09 12:18:33 +01:00

26 lines
585 B
JavaScript

'use strict';
function JobsCounter(maxJobsPerIntance, metadataBackend) {
this.metadataBackend = metadataBackend;
this.maxJobsPerIntance = maxJobsPerIntance || global.settings.max_jobs_per_instance;
this.hosts = {};
}
JobsCounter.prototype.increment = function (host) {
if (this[host] < this.maxJobsPerHost) {
this[host] += 1;
return true;
}
return false;
};
JobsCounter.prototype.decrement = function (host) {
if (this[host] > 0) {
this[host] -= 1;
return true;
}
return false;
};
module.exports = JobsCounter;