fix bug in retrying logic for reserve status

This commit is contained in:
Florian Dold 2016-09-26 18:00:21 +02:00
parent c89c90b7fa
commit 211e8c25d5
3 changed files with 1014 additions and 632 deletions

File diff suppressed because it is too large Load Diff

View File

@ -86,6 +86,9 @@ export class ChromeBadge implements Badge {
constructor(window?: Window) { constructor(window?: Window) {
// Allow injecting another window for testing // Allow injecting another window for testing
let bg = window || chrome.extension.getBackgroundPage(); let bg = window || chrome.extension.getBackgroundPage();
if (!bg) {
throw Error("no window available");
}
this.canvas = bg.document.createElement("canvas"); this.canvas = bg.document.createElement("canvas");
// Note: changing the width here means changing the font // Note: changing the width here means changing the font
// size in draw() as well! // size in draw() as well!
@ -221,4 +224,4 @@ export class ChromeBadge implements Badge {
stopBusy() { stopBusy() {
this.isBusy = false; this.isBusy = false;
} }
} }

View File

@ -612,8 +612,7 @@ export class Wallet {
* First fetch information requred to withdraw from the reserve, * First fetch information requred to withdraw from the reserve,
* then deplete the reserve, withdrawing coins until it is empty. * then deplete the reserve, withdrawing coins until it is empty.
*/ */
private processReserve(reserveRecord: any): void { private processReserve(reserveRecord: any, retryDelayMs: number = 250): void {
let retryDelayMs = 100;
const opId = "reserve-" + reserveRecord.reserve_pub; const opId = "reserve-" + reserveRecord.reserve_pub;
this.startOperation(opId); this.startOperation(opId);
this.updateExchangeFromUrl(reserveRecord.exchange_base_url) this.updateExchangeFromUrl(reserveRecord.exchange_base_url)
@ -633,11 +632,10 @@ export class Wallet {
return Query(this.db).put("history", depleted).finish(); return Query(this.db).put("history", depleted).finish();
}) })
.catch((e) => { .catch((e) => {
console.error("Failed to deplete reserve"); // random, exponential backoff truncated at 3 minutes
console.error(e); let nextDelay = Math.min(2 * retryDelayMs + retryDelayMs * Math.random(), 3000 * 60);
setTimeout(() => this.processReserve(reserveRecord), retryDelayMs); console.warn(`Failed to deplete reserve, trying again in ${retryDelayMs} ms`);
// exponential backoff truncated at one minute setTimeout(() => this.processReserve(reserveRecord, nextDelay), retryDelayMs);
retryDelayMs = Math.min(retryDelayMs * 2, 1000 * 60);
}); });
} }