Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added gitignore and added retries for failed batch attempts #43

Open
wants to merge 8 commits into
base: master
from
@@ -0,0 +1,3 @@
# Created by .ignore support plugin (hsz.mobi)
.idea
node_modules

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

@@ -146,16 +146,51 @@


},
track: function(data) {
track: function (data, attempts) {
// inject session id
data.sessionId = this.session_id;

var self = this;

//track number of attempts to publish
var attemptCounter = 0;
if(attempts) {
attemptCounter = attempts;
}

var postTimeout;

try {
//creating an asynchronous XMLHttpRequest
var xmlHttp = new XMLHttpRequest();
xmlHttp.open('POST', this.inputUrl, true); //true for asynchronous request
xmlHttp.setRequestHeader('Content-Type', 'text/plain');
xmlHttp.send(JSON.stringify(data));
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState === 4 && xmlHttp.status === 0) {
if(attemptCounter <= 12) {
console.log("Failed to log to loggly because of a network condition.");
console.log("Will attempt to log again in 5 seconds.");

postTimeout = setTimeout(function() {
self.track(data, attemptCounter + 1)
}, 5000);
} else {
console.log("Loggly has attempted to log this data for the last minute and failed. Ceasing" +
" attempts to log.");
console.log("Failed log data:", data);

clearTimeout(postTimeout);
}
} else if (xmlHttp.status === 200 || xmlHttp.status === 304) {
// It will only run this if there was a previous failure
if(postTimeout) {
console.log("Successfully logged to loggly.");
clearTimeout(postTimeout);
attemptCounter = 0;
}
}
};

} catch (ex) {
if (window && window.console && typeof window.console.log === 'function') {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.