Permalink
Browse files

Send 500 events at a time and wait between sends.

  • Loading branch information...
1 parent 0211438 commit 44f1ac8e5b185aac0599a2ae7cb039fb443c6a9e @trotter trotter committed May 11, 2012
Showing with 5 additions and 4 deletions.
  1. +5 −4 lib/cube/emitter-http.js
View
@@ -9,10 +9,10 @@ module.exports = function(protocol, host, port) {
if (protocol != "http:") throw new Error("invalid HTTP protocol");
function send() {
- var event = queue.shift();
- if (!event) return;
+ var events = queue.splice(0, 500);
+ if (events.length === 0) return;
- var body = JSON.stringify(event);
+ var body = JSON.stringify(events);
var postOptions = {
host: host,
@@ -26,11 +26,12 @@ module.exports = function(protocol, host, port) {
};
var postRequest = http.request(postOptions, function(res) {
- if (queue.length) process.nextTick(send);
+ if (queue.length) setTimeout(send, 500);
});
postRequest.on('error', function (e) {
console.warn(e.message);
+ // TODO: Add events back to queue on error
});
postRequest.write(body);

0 comments on commit 44f1ac8

Please sign in to comment.