Created
December 4, 2013 14:40
-
-
Save jtsoi/7788515 to your computer and use it in GitHub Desktop.
A simple client that spews out as many jobs as it can with a single fivebeans client to beanstalkd.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fivebeans = require('./index'); | |
var clients = 1; | |
var sent = 0; | |
function monitor() { | |
console.log("Events sent: "+sent); | |
sent = 0; | |
} | |
function startWork(client){ | |
client.put(fivebeans.LOWEST_PRIORITY, 0, 2, Array(300).join("b"), | |
function(err, jid){ | |
if(err || client.error){ | |
console.log("Error, stoping work..."); | |
return; | |
} | |
sent++; | |
startWork(client); | |
} | |
); | |
} | |
for(var i = 0; i < clients; i++){ | |
var client = new fivebeans.client('localhost', 11300); | |
client.on("connect", function(){ | |
client.error = false; | |
console.log("Connected, starting work..."); | |
startWork(client); | |
}); | |
client.on("error", function(err){ | |
client.error = true; | |
}); | |
client.on("close", function(err){ | |
setTimeout(function(){client.connect();}, 5000); | |
}); | |
client.connect(); | |
} | |
setInterval(monitor, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment