Skip to content

Commit d8a62e5

Browse files
committed
better indicator for failing country indicator updates
1 parent b679941 commit d8a62e5

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

data_source_mock/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const app = express()
66
const PORT = process.env.PORT || 3000
77
const BROKEN_SANCTIONS = process.env.BROKEN_SANCTIONS || false
88
const BROKEN_COUNTRIES = process.env.BROKEN_COUNTRIES || false
9+
const BROKEN_INDICATORS = process.env.BROKEN_INDICATORS || false
910

1011
let sentMail = []
1112

@@ -97,6 +98,11 @@ app.get('/country/:countryCode/indicator/:indicatorCode', async (req, res) => {
9798

9899
console.log('MOCK', code, indicatorCode, '(' + countryCode + ')')
99100

101+
if (BROKEN_INDICATORS && !req.query.ok && countryCode[0] == 'B') {
102+
console.log('MOCK country indicators, broken', BROKEN_INDICATORS)
103+
return res.status(Number(BROKEN_INDICATORS)).send({ message: 'errored' })
104+
}
105+
100106
res.json(JSON.parse(data))
101107
})
102108

@@ -111,4 +117,5 @@ app.listen(PORT, () => {
111117
console.log('MOCK started in port', PORT)
112118
console.log('BROKEN_SANCTIONS', BROKEN_SANCTIONS)
113119
console.log('BROKEN_COUNTRIES', BROKEN_COUNTRIES)
120+
console.log('BROKEN_INDICATORS', BROKEN_INDICATORS)
114121
})

src/server/data/worldbank/util.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,12 @@ export const buildCache = async () => {
171171
} catch (e) {
172172
failed.push(code)
173173
}
174-
try {
175-
await cacheCountryIndicator(code, 'CC.PER.RNK')
176-
await cacheCountryIndicator(code, 'PV.PER.RNK')
177-
} catch (e) {
174+
const cc = await cacheCountryIndicator(code, 'CC.PER.RNK')
175+
if (!cc) {
176+
failed.push(code)
177+
}
178+
const pv = await cacheCountryIndicator(code, 'PV.PER.RNK')
179+
if (!pv) {
178180
failed.push(code)
179181
}
180182

@@ -207,10 +209,13 @@ export const buildIndividualCountryCaches = async () => {
207209
} catch (e) {
208210
failed.push(code)
209211
}
210-
try {
211-
await cacheCountryIndicator(code, 'CC.PER.RNK')
212-
await cacheCountryIndicator(code, 'PV.PER.RNK')
213-
} catch (e) {
212+
213+
const cc = await cacheCountryIndicator(code, 'CC.PER.RNK')
214+
if (!cc) {
215+
failed.push(code)
216+
}
217+
const pv = await cacheCountryIndicator(code, 'PV.PER.RNK')
218+
if (!pv) {
214219
failed.push(code)
215220
}
216221

0 commit comments

Comments
 (0)