0
votes

Using Firebase Functions, I have code that runs every hour via a Google Cloud Scheduler Job.

It looks like this:

exports.hourly_tick =
  functions.pubsub.topic("hourly-tick").onPublish((message, context) => {
    return getData()
      .then((data) => {
          sendEmail(data["message"]);
      })
      .catch((error) => {
        return console.log("???? Caught error: ", error);
      });
  });

I need to be able to test this locally, and am able to start my Firebase Emulator via firebase emulators:start from my terminal. However I do not know how to trigger this function in my local test environment to see logs in the local emulator.

How can I test this scheduled job / firebase function with the local emulator?

1

1 Answers

0
votes

This is an ongoing feature request in Firebase tools (see GitHub issue).

As mentioned in the thread:

I think we maybe misled with how we represented #2011. It lets those functions be loaded into the emulator but doesn't actually trigger them on a schedule. Instead you'd have to manually trigger them using a Pub/Sub message.

You can check a workaround on this answer where you'd have to manually trigger a scheduled function using a Pub/Sub message.