我是 Firebase 新手,现在我正在尝试制作计划功能。
所以我尝试了这个,看看日程功能是否有效。
exports.testSchedule = functions.pubsub
.schedule('*/1 * * * *') // every one minute.
.timeZone('America/New_York')
.onRun(async (context) => {
console.log("Hello world")
functions.logger.info("Hello world");
});
我启动了 Firebase 模拟器
firebase emulators:start
然后我等了10多分钟,但我看不到来自console.log()或logger.info()的任何日志 请让我知道我的代码有什么问题。 谢谢你。
Firebase 模拟器目前不支持计划功能。我认为这里的问题是函数
testSchedule
没有被触发,而不是 console.log
和 functions.logger.info
不起作用。
您应该能够使用下面的代码片段来验证这一点:
const functions = require("firebase-functions/v1");
exports.helloWorld = functions.https.onRequest((req, res) => {
functions.logger.info("Hello world");
return res.send("Hello world")
})
在“http://127.0.0.1:5001/PROJECT_ID/us-central1/helloWorld”上调用函数端点应显示日志消息:
i functions: Beginning execution of "us-central1-helloWorld"
> {"severity":"INFO","message":"Hello world"}
i functions: Finished "us-central1-helloWorld" in 3.4885ms
或者,如果您想运行预定的函数,您可以使用
firebase functions:shell
命令,然后在那里调用该函数。即
firebase > testSchedule()
日志会显示:
'Successfully invoked function.'
firebase > > Hello world
> {"severity":"INFO","message":"Hello world"}