Search code examples
firebasegoogle-cloud-functionsgoogle-cloud-pubsubfirebase-tools

Google Cloud Functions Cron Job Not Working: "function ignored because the pubsub emulator does not exist or is not running"


I am trying to set up a scheduled function in Firebase Cloud Functions. As a simple test, I have tried to recreate the sample shown on the documentation page:

const functions = require('firebase-functions')

exports.scheduledFunction = functions.pubsub
  .schedule('every 5 minutes')
  .onRun(context => {
    console.log('This will be run every 5 minutes!')
    return null
  })

However, when I run firebase serve --only functions, I get the following error:

function ignored because the pubsub emulator does not exist or is not running.

Any idea why I get this message and how I can fix it?


Solution

  • From the documentation on Firebase's local emulator:

    The Firebase CLI includes a Cloud Functions emulator which can emulate the following function types:

    • HTTPS functions
    • Callable functions
    • Cloud Firestore functions

    So the local Firebase emulators don't currently support pubsub, and the error message seems to confirm that. So for the moment, you can't run pubsub triggered Cloud Functions locally.

    A feature request for adding PubSub support to the emulator was filed. You might want to read up (and possibly comment) there, as the direction taken may or may not match with your needs.

    The local shell does support invoking pubsub functions. That is of course quite different, but might be useful as a workaround for the moment.