kopia lustrzana https://github.com/badgen/badgen.net
refactor: use got in travis
rodzic
6e46679011
commit
2f2b3876eb
|
@ -1,5 +1,7 @@
|
||||||
const got = require('got')
|
const got = require('got')
|
||||||
|
|
||||||
module.exports = got.extend({
|
module.exports = got.extend({
|
||||||
json: true
|
json: true,
|
||||||
|
timeout: 3200,
|
||||||
|
retry: 0
|
||||||
})
|
})
|
||||||
|
|
|
@ -3,10 +3,11 @@ const pool = require('./live-pool.js')
|
||||||
const raven = require('./raven.js')
|
const raven = require('./raven.js')
|
||||||
|
|
||||||
module.exports = async (service, fn, paramsPath) => {
|
module.exports = async (service, fn, paramsPath) => {
|
||||||
|
const fetchStart = new Date()
|
||||||
const fetchKey = `#${service}/${paramsPath}`
|
const fetchKey = `#${service}/${paramsPath}`
|
||||||
|
|
||||||
if (pool.has(fetchKey)) return pool.get(fetchKey)
|
if (pool.has(fetchKey)) return pool.get(fetchKey)
|
||||||
|
|
||||||
const fetchStart = new Date()
|
|
||||||
const fetcher = fn(...paramsPath.split('/')).then(
|
const fetcher = fn(...paramsPath.split('/')).then(
|
||||||
result => {
|
result => {
|
||||||
console.log(timeSince(fetchStart), fetchKey)
|
console.log(timeSince(fetchStart), fetchKey)
|
||||||
|
@ -14,9 +15,9 @@ module.exports = async (service, fn, paramsPath) => {
|
||||||
},
|
},
|
||||||
err => errorHandler(service, paramsPath, err)
|
err => errorHandler(service, paramsPath, err)
|
||||||
).finally(() => {
|
).finally(() => {
|
||||||
console.log(timeSince(fetchStart), fetchKey)
|
|
||||||
pool.delete(fetchKey)
|
pool.delete(fetchKey)
|
||||||
})
|
})
|
||||||
|
|
||||||
pool.set(fetchKey, fetcher)
|
pool.set(fetchKey, fetcher)
|
||||||
|
|
||||||
return fetcher
|
return fetcher
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const axios = require('../axios.js')
|
const got = require('../got.js')
|
||||||
|
|
||||||
const statuses = [
|
const statuses = [
|
||||||
['passed', 'green'],
|
['passed', 'green'],
|
||||||
|
@ -17,8 +17,8 @@ module.exports = async (user, repo, branch = 'master') => {
|
||||||
const com = `https://api.travis-ci.com/${user}/${repo}.svg?branch=${branch}`
|
const com = `https://api.travis-ci.com/${user}/${repo}.svg?branch=${branch}`
|
||||||
const org = `https://api.travis-ci.org/${user}/${repo}.svg?branch=${branch}`
|
const org = `https://api.travis-ci.org/${user}/${repo}.svg?branch=${branch}`
|
||||||
const [svg1, svg2] = await Promise.all([
|
const [svg1, svg2] = await Promise.all([
|
||||||
axios(com).then(({ data }) => data).catch(e => undefined),
|
got(com, { json: false }).then(({ body }) => body),
|
||||||
axios(org).then(({ data }) => data).catch(e => undefined)
|
got(org, { json: false }).then(({ body }) => body)
|
||||||
])
|
])
|
||||||
|
|
||||||
const result = statuses.find(st => {
|
const result = statuses.find(st => {
|
||||||
|
|
Ładowanie…
Reference in New Issue