Skip to content
Snippets Groups Projects
Commit 0d93f3e0 authored by Xiao Gui's avatar Xiao Gui
Browse files

bugfix: ready probe

parent 5d690f22
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,7 @@ const MemoryStore = require('memorystore')(session)
const crypto = require('crypto')
const cookieParser = require('cookie-parser')
const { router: regionalFeaturesRouter, regionalFeaturesIsReady } = require('./regionalFeatures')
const { router: regionalFeaturesRouter, regionalFeatureIsReady } = require('./regionalFeatures')
const LOCAL_CDN_FLAG = !!process.env.PRECOMPUTED_SERVER
......@@ -166,7 +166,7 @@ app.use('/logo', require('./logo'))
app.get('/ready', async (req, res) => {
const authIsReady = await authReady()
const regionalFeatureReady = await regionalFeaturesIsReady()
const regionalFeatureReady = await regionalFeatureIsReady()
const allReady = [
authIsReady,
regionalFeatureReady,
......@@ -176,7 +176,7 @@ app.get('/ready', async (req, res) => {
*/
].every(f => !!f)
if (allReady) return res.status(200).end()
else return res.status(400).end()
else return res.status(500).end()
})
/**
......
......@@ -18,12 +18,15 @@ const regionIdToDataIdMap = new Map()
const datasetIdToDataMap = new Map()
const datasetIdDetailMap = new Map()
let isReady = false
const ITERABLE_KEY_SYMBOL = Symbol('ITERABLE_KEY_SYMBOL')
/**
* this pattern allows all of the special data to be fetched in parallel
* async await would mean it is fetched one at a time
*/
const init = Promise.all(
arrayToFetch.map(url =>
new Promise((rs, rj) => {
......@@ -70,7 +73,7 @@ const init = Promise.all(
})
})
)
)
).then(() => isReady = true)
const getFeatureMiddleware = (req, res, next) => {
const { featureFullId } = req.params
......@@ -213,10 +216,7 @@ router.get(
sendFeatureDataResponse,
)
const regionalFeatureIsReady = () => Promise.race([
init.then(() => true),
new Promise(rs => setTimeout(() => rs(false), 500))
])
const regionalFeatureIsReady = async () => isReady
module.exports = {
router,
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment