1

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?

vikzilla
  • 3,998
  • 6
  • 36
  • 57

1 Answers1

0

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.

Donnald Cucharo
  • 3,866
  • 1
  • 10
  • 17
  • 1
    I am thinking of just copying the logic into an http request export as well. So for testing I can just hit that endpoint while running the emulator. – vikzilla May 07 '21 at 05:31
  • Yes running the function as HTTP triggered for testing should be fine for testing purpose. Just need to set the pushEndpoint to the HTTP request endpoint. Also, make sure to revert it to pub/sub event triggered before deploying it – Ras Oct 04 '22 at 04:47