I have a firebase https function (uses onRequest). It gets 3800 categories, and batches them into promises.
let categoryCount = 0
while (categories.length) {
await Promise.all([
...categories.splice(0, 5).map((category) => {
const { id, level } = category
let productCountPromise = null
// *- Only check for level 3 and above
if (level >= 3) {
productCountPromise = getProductCount(appId, id)
}
categoryCount += 1
return productCountPromise
? productCountPromise.then((productCount) => {
console.log(`Category: ${id} Level: ${level} Count: ${productCount}`)
if (productCountPromise <= 0) {
categoryIdsToHide.push(id)
} else if (productCountPromise > 0) {
categoryIdsToShow.push(id)
}
})
: productCountPromise
}),
() => new Promise((resolve) => setTimeout(resolve, 1000)),
])
}
This function runs 5 HTTP request and waits 1000 ms so that the API can recover. The API is not timing out, but the firebase function just stops and never goes past this while loop. Do I have a unresolved promise somehow? The function will run for about 6 minutes and it stops on varying number of categories.
There’s no error, and the timeout is set for 60 min on v2 firebase functions.