0

I created a firebase cloud function that runs every minute to update some data in cloud firestore. The logic of the code is right, as I have tested in at frontend. However, after I deployed the function, nothing was logged on the firebase console except for the 2 messages I got upon deployment. I tested it with firebase emulators, and no information was logged on the functions emulator either, while it did show that "pubsub function initialized." I went to the port where the pubsub emulator ran on, and there was an "Ok" on the page. Besides, there were no errors logged on either firebase console or functions emulator. I am confused.

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
}

Xi Liu
  • 559
  • 9
  • 18

0 Answers0