0

I'm new to Firebase and now I'm trying to make a schedule function.

So I tried this one to see if the schedule function works.

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");
  });

And I started Firebase emulator

firebase emulators:start

It seems like works properly. screenshot of terminal

Then I waited more than 10 mins but I could not see any log from console.log() or logger.info() Please let me know what's wrong with my code. Thank you.

2
  • On Stack Overflow, please don't show pictures of text and code. Copy the text into the question itself and format it so that it's easy to read, copy, and search. You can edit the question to correct this using the edit link at the bottom. Commented Jan 8, 2024 at 17:50
  • Also please copy the entire output of the Firebase CLI into your question, not just what you have now. Commented Jan 8, 2024 at 17:51

1 Answer 1

0

Firebase Emulator currently does not support scheduled functions. I think the problem here is that the function testSchedule is not being triggered, and not console.log and functions.logger.info not working.

You should be able to verify this using the code snippet below:

const functions = require("firebase-functions/v1");

exports.helloWorld = functions.https.onRequest((req, res) => {
    functions.logger.info("Hello world");
    return res.send("Hello world")
})

Calling the function endpoint on "http://127.0.0.1:5001/PROJECT_ID/us-central1/helloWorld" should show the log message:

i  functions: Beginning execution of "us-central1-helloWorld"
>  {"severity":"INFO","message":"Hello world"}
i  functions: Finished "us-central1-helloWorld" in 3.4885ms

Alternatively, if you want to run the scheduled function, you can use the firebase functions:shell command then invoke the function there. i.e

firebase > testSchedule()

Logs would show:

'Successfully invoked function.'
firebase > >  Hello world
>  {"severity":"INFO","message":"Hello world"}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.