我正在尝试设置一个 scheduled function在 Firebase 云函数中。作为一个简单的测试,我尝试重新创建文档页面上显示的示例:
const functions = require('firebase-functions')
exports.scheduledFunction = functions.pubsub
.schedule('every 5 minutes')
.onRun(context => {
console.log('This will be run every 5 minutes!')
return null
})
但是,当我运行
firebase serve --only functions
时,我收到以下错误:function ignored because the pubsub emulator does not exist or is not running.
知道为什么我会收到此消息以及如何修复它吗?
最佳答案
来自 Firebase's local emulator 上的文档:
The Firebase CLI includes a Cloud Functions emulator which can emulate the following function types:
- HTTPS functions
- Callable functions
- Cloud Firestore functions
所以本地 Firebase 模拟器目前不支持 pubsub,错误消息似乎证实了这一点。因此,目前您无法在本地运行 pubsub 触发的 Cloud Functions。
adding PubSub support to the emulator 的功能请求被归档。您可能想在那里阅读(并可能发表评论),因为所采取的方向可能符合也可能不符合您的需求。
本地shell 支持 invoking pubsub functions .这当然是完全不同的,但作为目前的解决方法可能很有用。
关于firebase - Google Cloud Functions Cron 作业不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59346125/