Firebase Cloud Function scheduled function not running

Viewed 1621

I'm attempting my first scheduled cloud function. To test, I'm trying to run it every 1 minute and will increase later.

I've deployed it but haven't yet seen it run via the Firebase Logs.

Here's what I've deployed:

const fetchMovies = require('./data/fetchMovies');
exports.fetchMovies = functions.pubsub.schedule('every 1 minute').onRun((context) => {
  console.log("Running, with this context:", context)
  fetchMovies.handler(db);
});

Any idea what may be incorrect here?

2 Answers

From the docs

A 5 minute example...

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

Both Unix Crontab and AppEngine syntax are supported by Google Cloud Scheduler.

exports.scheduledFunctionCrontab = functions.pubsub.schedule('5 11 * * *')
  .timeZone('America/New_York') // Users can choose timezone - default is America/Los_Angeles
  .onRun((context) => {
  console.log('This will be run every day at 11:05 AM Eastern!');
  return null;
});

To trigger a function every minute use the string '* * * * *'. Thats every minute in unix. Don't forget that every * must separated from each other with a space

Like:

const fetchMovies = require('./data/fetchMovies');

exports.fetchMovies = functions.pubsub.schedule('* * * * *').onRun((context) => {
  console.log("Running, with this context:", context)
  fetchMovies.handler(db);
});
Related