2015-12-16 22:57:58 +08:00
|
|
|
'use strict';
|
|
|
|
|
2015-12-29 17:19:10 +08:00
|
|
|
var JobQueue = require('./job_queue');
|
|
|
|
|
|
|
|
function JobQueuePool(metadataBackend) {
|
|
|
|
this.metadataBackend = metadataBackend;
|
2015-12-16 22:57:58 +08:00
|
|
|
this.queues = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
JobQueuePool.prototype.get = function (host) {
|
|
|
|
return this.queues[host];
|
|
|
|
};
|
|
|
|
|
2016-01-13 23:25:25 +08:00
|
|
|
JobQueuePool.prototype.getQueue = function (host) {
|
|
|
|
if (this.get(host)) {
|
|
|
|
return this.get(host).queue;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-01-25 21:51:37 +08:00
|
|
|
JobQueuePool.prototype.removeQueue = function (host) {
|
|
|
|
if (this.queues[host].queue) {
|
|
|
|
delete this.queues[host].queue;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-12-16 22:57:58 +08:00
|
|
|
JobQueuePool.prototype.list = function () {
|
|
|
|
return Object.keys(this.queues);
|
|
|
|
};
|
|
|
|
|
2016-01-13 23:25:25 +08:00
|
|
|
JobQueuePool.prototype.createQueue = function (host) {
|
|
|
|
this.queues[host] = {
|
|
|
|
queue: new JobQueue(this.metadataBackend),
|
|
|
|
currentJobId: null
|
|
|
|
};
|
|
|
|
|
|
|
|
return this.getQueue(host);
|
|
|
|
};
|
|
|
|
|
|
|
|
JobQueuePool.prototype.setCurrentJobId = function (host, job_id) {
|
|
|
|
this.get(host).currentJobId = job_id;
|
2015-12-16 22:57:58 +08:00
|
|
|
};
|
|
|
|
|
2016-01-25 21:51:37 +08:00
|
|
|
JobQueuePool.prototype.getCurrentJobId = function (host) {
|
|
|
|
if (this.get(host).currentJobId) {
|
|
|
|
return this.get(host).currentJobId;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
JobQueuePool.prototype.removeCurrentJobId = function (host) {
|
|
|
|
if (this.get(host).currentJobId) {
|
|
|
|
delete this.get(host).currentJobId;
|
|
|
|
}
|
2015-12-16 22:57:58 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = JobQueuePool;
|