Skip to content
This repository has been archived by the owner on May 31, 2020. It is now read-only.

Redis Backend problems fixed #82

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions celery.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ function RedisBroker(broker_url) {
database = purl.pathname.slice(1);
}

self.redis = redis.createClient(purl.port || 6379,
purl.hostname || 'localhost');

debug('Connecting to broker...');
if (purl.auth) {
self.redis = redis.createClient(purl.port || 6379, purl.hostname || 'localhost', {'auth_pass': purl.auth.split(':')[1]});
debug('Authenticating broker...');
self.redis.auth(purl.auth.split(':')[1]);
debug('Broker authenticated...');
} else {
self.redis = redis.createClient(purl.port || 6379,
purl.hostname || 'localhost');
}

if (database) {
Expand All @@ -89,6 +91,7 @@ function RedisBroker(broker_url) {
};

self.redis.on('connect', function() {
debug('Broker connected...');
self.emit('ready');
});

Expand Down Expand Up @@ -132,15 +135,19 @@ function RedisBackend(conf) {
var database;

if (purl.pathname) {
database = purl.pathname.slice(1);
database = purl.pathname.slice(1);
}

debug('Connecting to backend...');
if (purl.auth) {
self.redis = redis.createClient(purl.port, purl.hostname, {'auth_pass': purl.auth.split(':')[1]});
self.redis = redis.createClient(purl.port || 6379, purl.hostname || 'localhost', {'auth_pass': purl.auth.split(':')[1]});
debug('Authenticating broker...');
self.redis.auth(purl.auth.split(':')[1]);
debug('Broker authenticated...');
} else {
self.redis = redis.createClient(purl.port, purl.hostname);
self.redis = redis.createClient(purl.port || 6379, purl.hostname || 'localhost');
}

// needed because we'll use `psubscribe`
var backend_ex = self.redis.duplicate();

Expand Down Expand Up @@ -171,12 +178,19 @@ function RedisBackend(conf) {
debug('Backend connected...');
// on redis result..
self.redis.on('pmessage', function(pattern, channel, data) {
backend_ex.expire(channel, conf.TASK_RESULT_EXPIRES / 1000);

if(conf.CELERY_TASK_RESULT_DURABLE){
backend_ex.expire(channel, conf.TASK_RESULT_EXPIRES / 1000);
} else {
backend_ex.expire(channel, 0);
}

var message = JSON.parse(data);
var taskid = channel.slice(key_prefix.length);
if (self.results.hasOwnProperty(taskid)) {
var res = self.results[taskid];
res.result = message;

res.emit('ready', res.result);
delete self.results[taskid];
} else {
Expand All @@ -185,7 +199,7 @@ function RedisBackend(conf) {
}
});
// subscribe to redis results
self.redis.psubscribe(key_prefix + '*', () => {
self.redis.psubscribe(key_prefix + '[^php_]*', () => {
self.emit('ready');
});
});
Expand Down