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) {
// Allow injecting another window for testing
let bg = window || chrome.extension.getBackgroundPage();
if (!bg) {
throw Error("no window available");
}
this.canvas = bg.document.createElement("canvas");
// Note: changing the width here means changing the font
// size in draw() as well!

View File

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