【发布时间】:2019-11-28 16:29:03
【问题描述】:
我有一个 Firebase 云功能,每天在股市开市时触发一次。似乎在 20% 的时间运行时会产生错误。
错误说:'错误:函数崩溃超出请求范围函数调用被中断。'
export async function cleanIntraweek() {
console.log(`cleanIntraweek() started`)
const min_date_key = moment().tz("America/New_York").subtract(7, 'day').format()
console.log(`min_date_key: ${min_date_key}`)
//helper async function to grab some data
const enabled_stock_keys = await FirebaseObjectFetchService.getStockKeys(true)
const fetch_intraweek_dataset_promises: Promise<any>[] = []
const clear_data_promises: Promise<any>[] = []
for (const stock_key of enabled_stock_keys) {
const fetch_intraweek_dataset_promise =
db
.ref(`charts/${stock_key}/intraweek_v3`)
.orderByKey()
.endAt(min_date_key)
.once("value")
.then((snapshot) => {
snapshot.forEach((child_snapshot) => {
const clear_data_promise = child_snapshot.ref.remove()
clear_data_promises.push(clear_data_promise)
return false
});
})
fetch_intraweek_dataset_promises.push(fetch_intraweek_dataset_promise)
}
console.log("waiting on fetch_intraweek_dataset_promises")
await Promise.all(fetch_intraweek_dataset_promises)
console.log("waiting on clear_data_promises")
await Promise.all(clear_data_promises).then(() => {console.log("cleanIntraweek() finished")})
return null
}
我不记得当我的云功能在 Node 6 引擎上运行时出现此错误。从 Node 8 引擎(当前)恢复到 Node 6 引擎并不是一个解决方案,因为 Firebase Cloud Functions 将在一年内取消对 Node 6 引擎的支持。
我见过this post,但据我所知,在函数返回之前,我没有任何未等待的承诺。
【问题讨论】:
标签: typescript firebase async-await google-cloud-functions