CartoDB-SQL-API/batch/pubsub/job-publisher.js
Raul Ochoa 1f038ac1f4 Moves from host queues to user queues
- Existing jobs are moved before start processing them.
 - Uses a new queue prefix to avoid collisions.
 - Pub/Sub also changes communication channel.
 - Job subscriber emits user+host on new jobs.
 - Batch processor is faulty. See TODO in batch.js.
2016-10-12 21:32:29 +02:00

32 lines
839 B
JavaScript

'use strict';
var Channel = require('./channel');
var debug = require('./../util/debug')('pubsub:publisher');
var error = require('./../util/debug')('pubsub:publisher:error');
function JobPublisher(pool) {
this.pool = pool;
}
JobPublisher.prototype.publish = function (user) {
var self = this;
this.pool.acquire(Channel.DB, function (err, client) {
if (err) {
return error('Error adquiring redis client: ' + err.message);
}
client.publish(Channel.NAME, user, function (err) {
self.pool.release(Channel.DB, client);
if (err) {
return error('Error publishing to ' + Channel.NAME + ':' + user + ', ' + err.message);
}
debug('publish to ' + Channel.NAME + ':' + user);
});
});
};
module.exports = JobPublisher;