Skip to content
This repository has been archived by the owner on Feb 16, 2020. It is now read-only.

Commit

Permalink
[plugin] add basic retry to candleUploader
Browse files Browse the repository at this point in the history
  • Loading branch information
askmike committed Jan 9, 2019
1 parent 25bb888 commit 1d5f9ce
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions plugins/candleUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ CandleUploader.prototype.schedule = function() {
this.timer = setTimeout(this.upload, 10 * 1000);
}

CandleUploader.prototype.upload = function() {
const amount = this.candles.length;
if(!amount) {
return this.schedule();
}
CandleUploader.prototype.rawUpload = function(candles, count, next) {

axios({
url: config.candleUploader.url,
Expand All @@ -41,12 +37,32 @@ CandleUploader.prototype.upload = function() {
console.log('error uploading:', r.data);
}
console.log(new Date, 'uploaded', amount, 'candles');
this.schedule();

next();
})
.catch(e => {
console.log('error uploading:', e.message);
this.schedule();

count++;

if(count > 10) {
console.log('FINAL error uploading:', e.message);
return next();
}

setTimeout(() => this.rawUpload(candles, count, next), 2000);
});
}

CandleUploader.prototype.upload = function() {
const amount = this.candles.length;
if(!amount) {
return this.schedule();
}

this.rawUpload(this.candles, 0, () => {
this.schedule();
});

this.candles = [];
}
Expand Down

0 comments on commit 1d5f9ce

Please sign in to comment.