Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pgte committed Sep 10, 2011
0 parents commit a892ffb
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
dump.rb
node_modules
3 changes: 3 additions & 0 deletions README.md
@@ -0,0 +1,3 @@
# banzai-redis

Redis queueing plugin module for Banzai.
31 changes: 31 additions & 0 deletions index.js
@@ -0,0 +1,31 @@
var kue = require('kue')
, redis = require('redis');

module.exports = function(config) {
var jobs;

config = config || {};

kue.redis.createClient = function() {
var client = redis.createClient(config.port || 6379, config.host || '127.0.0.1');
if (config.password) { client.auth(config.password); }
return client;
};

jobs = kue.createQueue();

function push(type, job, done) {
jobs.create(type, job).save(done);
};

function pop(type, callback) {
jobs.process(type, function(job, done) {
callback(job.data, done);
});
}

return {
push: push
, pop: pop
}
};
19 changes: 19 additions & 0 deletions package.json
@@ -0,0 +1,19 @@
{ "name" : "banzai-redis"
, "description" : "Redis queueing plugin module for Banzai"
, "tags" : ["ETL", "pipeline", "document", "state machine", "redis", "queue", "banzai"]
, "version" : "0.1.0"
, "author" : "Pedro Teixeira <pedro.teixeira@gmail.com>"
, "repository" :
{ "type" : "git"
, "url" : "http://github.com/pgte/banzai-redis.git"
}
, "bugs" :
{ "web" : "http://github.com/pgte/banzai-redis/issues" }
, "engines" : ["node >= 0.4.10"]
, "main" : "./index"
, "dependencies": {
"kue": "0.2.0"
, "redis": "0.6.0"
}
, "scripts": { "test": "make" }
}
56 changes: 56 additions & 0 deletions test.js
@@ -0,0 +1,56 @@
var queue = require('./')()
, assert = require('assert');

setTimeout(function() {
process.exit();
}, 5000)

exports.push_then_pop = function(done) {
var job = {a: 1, b: 2}
, cb1 = false;

queue.push('test1', job);
queue.pop('test1', function(retjob, done) {
assert.ok(! cb1);
assert.eql(job, retjob);
cb1 = true;
done();
});

done(function() {
assert.ok(cb1);
})
};

exports.pop_then_push = function(done) {
var job = {a: 2, b: 2}
, cb1 = false;

queue.pop('test2', function(retjob, done) {
assert.ok(! cb1);
assert.eql(job, retjob);
cb1 = true;
done();
});
queue.push('test2', job);

done(function() {
assert.ok(cb1);
})
};

exports.pop_no_push = function(done) {
var job = {a: 3, b: 2}
, cb1 = false;

queue.pop('test3', function(retjob, done) {
assert.ok(! cb1);
assert.eql(job, retjob);
cb1 = true;
done();
});

done(function() {
assert.ok(! cb1);
})
};

0 comments on commit a892ffb

Please sign in to comment.