Javascript async await Firebase云函数包含三条等待行时超时
似乎每当我在代码中添加第三个WAIT语句时,就会导致firebase函数超时 一些tldr背景: 我正在创建一个推送通知服务器,它有一个支持每周定期通知的管理后端。云功能计划每分钟运行一次。它基本上执行以下psuedo代码:Javascript async await Firebase云函数包含三条等待行时超时,javascript,firebase,async-await,google-cloud-functions,Javascript,Firebase,Async Await,Google Cloud Functions,似乎每当我在代码中添加第三个WAIT语句时,就会导致firebase函数超时 一些tldr背景: 我正在创建一个推送通知服务器,它有一个支持每周定期通知的管理后端。云功能计划每分钟运行一次。它基本上执行以下psuedo代码: await: retrieve the list of notifications from the firebase database if: any notifications have a timestamp that is at or before the curr
await: retrieve the list of notifications from the firebase database
if: any notifications have a timestamp that is at or before the current moment
await: write a new rescheduled timestamp to the firebase database
await: send out the notifications
return
如果我注释掉后两个等待中的任何一个,函数将在大约500毫秒内完全执行,但每当我同时运行它们时,函数将运行到超时(60秒)
下面是完整的函数(typescript)
export const heartbeat=functions.pubsub.schedule('*/1****').onRun(异步事件=>{
log(“哟,这v1.0.32每分钟心跳一次!”)
const db=admin.firestore()
//查找在当前时间之前或当前时间具有triggerTimes的主题
const timeTableSnapshot=await db.collection('fcmTimetable')。其中('triggerTime',此代码以一种非常奇怪的方式将async/await与then/catch回调混合在一起。一般来说,如果正确使用async/await,则不需要then/catch。如果此函数超时,请查看每个异步函数所用的总时间(使用日志语句)如果默认的60秒太短,则增加函数的超时时间。哇,真的很简单!我从sendAll和commit的末尾删除了捕获,然后一切都按预期进行了。我一直在为这个问题绞尽脑汁。谢谢你,Doug!