Skip to content

Commit

Permalink
Allow preventing queue from containing duplicates
Browse files Browse the repository at this point in the history
Closes #8
  • Loading branch information
Sandro Santilli committed Feb 12, 2014
1 parent d223bc0 commit b149baf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Versions 0.2.0
- Fix EventEmitter inheritance
- Logging is now optional: client.debug = true;
- "ready_callback" now gets 2 params: err and clientInstance
- Allow preventing queue from containing duplicates

Versions 0.1.1
2012-07-10
Expand Down
6 changes: 5 additions & 1 deletion lib/node-varnish/varnish_queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ function VarnishQueue(host, port, secret) {
});
}

self.run_cmd = function(cmd) {
self.run_cmd = function(cmd, nodup) {
if ( nodup && queue.indexOf(cmd) != -1 ) {
log("skip duplicated varnish command in queue: " + cmd);
return;
}
queue.push(cmd);
if(queue.length > MAX_QUEUE) {
console.log("varnish command queue too long, removing commands");
Expand Down
14 changes: 14 additions & 0 deletions test/acceptance/varnish.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,20 @@ suite('varnish', function() {
});
});
});

test('should not send duplicate commands if asked', function(done) {
var server = new VarnishEmu();
server.on('listening', function() {
var queue = new varnish.VarnishQueue('127.0.0.1', server.address().port);
for(var i = 0; i < 5; ++i) {
queue.run_cmd('purge ' + (i%2), true);
}
queue.on('empty', function() {
assert.equal(2, server.commands);
done();
});
});
});

test('should send commands on connect', function(done) {
// first create queue
Expand Down

0 comments on commit b149baf

Please sign in to comment.