我创建了一个Firebase云功能,该功能每分钟运行一次以更新Cloud Firestore中的某些数据。正如我在前端所测试的那样,代码的逻辑是正确的。但是,部署功能后,除了在部署时收到的2条消息外,firebase控制台上没有记录任何内容。我用firebase模拟器进行了测试,功能模拟器上也没有记录任何信息,但确实显示了“ pubsub函数已初始化”。我去了运行pubsub仿真器的端口,页面上有一个“ OK”。此外,在Firebase控制台或功能仿真器上均未记录任何错误。我很困惑。
index.js
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const serviceAccount = require('./ServiceAccountKey.json')
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
})
exports.scheduledFunction = functions.pubsub.schedule('every 1 minute').onRun((context) => {
var rooms = [];
var open;
console.log("start");
const db = admin.firestore();
db.collection("rooms").get().
then((query) => {
console.log(query.docs);
......
})
})
package.json
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "8"
},
"dependencies": {
"firebase-admin": "^8.10.0",
"firebase-functions": "^3.6.1"
},
"devDependencies": {
"firebase-functions-test": "^0.2.0"
},
"private": true
}