diff --git a/lib/failbot.js b/lib/failbot.js index 9bf5139a0377..42e7399060d7 100644 --- a/lib/failbot.js +++ b/lib/failbot.js @@ -1,8 +1,36 @@ import got from 'got' -import { Failbot, HTTPBackend, LogBackend } from '@github/failbot' +import { Failbot, HTTPBackend } from '@github/failbot' const HAYSTACK_APP = 'docs' +async function retryingGot(url, args) { + return got( + url, + Object.assign({}, args, { + // With the timeout at 3000 (milliseconds) and the retry.limit + // at 4 (times), the total worst-case is: + // 3000 * 4 + 1000 + 2000 + 3000 + 4000 + 8000 = 30 seconds + timeout: 3000, + retry: { + // This means it will wait... + // 1. 1000ms + // 2. 2000ms + // 3. 4000ms + // 4. 8000ms + // 5. give up! + // + // From the documentation: + // + // Delays between retries counts with function + // 1000 * Math.pow(2, retry - 1) + Math.random() * 100, + // where retry is attempt number (starts from 1). + // + limit: 4, + }, + }) + ) +} + export function report(error, metadata) { // If there's no HAYSTACK_URL set, bail early if (!process.env.HAYSTACK_URL) return @@ -10,12 +38,9 @@ export function report(error, metadata) { const backends = [ new HTTPBackend({ haystackURL: process.env.HAYSTACK_URL, - fetchFn: got, + fetchFn: retryingGot, }), ] - if (process.env.NODE_ENV !== 'test') { - backends.push(new LogBackend({ log: console.log.bind(console) })) - } const failbot = new Failbot({ app: HAYSTACK_APP, backends: backends,