Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions lib/failbot.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,46 @@
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

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,
Expand Down