How to run cron job with Firebase?

后端 未结 6 1216
南笙
南笙 2020-12-01 16:49

I am trying to run a cron job with Firebase. Basically I need to run a function that makes a ton of API calls and pushes data to firebase at 12:00am PST every day. Is there

6条回答
  •  遥遥无期
    2020-12-01 17:24

    To answer the question about how firebase-cron works:

    This module needs to be run on a server someplace so it's always on. When jobs are run, all this means is that it takes the specified data for that job and puts it into the specified firebase-queue reference. As a user, you set up the firebase-queue to run when the data is added to the queue.

    You can add a "cron" job by specifying the name, the cron pattern, and the data add to the queue using the .addJob method:

    cron.addJob('foo', '0 0 0 * * *', {foo: 'bar'}, function(err) {
      if (err) return console.error(err);
      console.log('added foo');
    });
    

    Use the .run method to start firebase-cron. This checks the list of jobs and executes any that needed to be executed. This method also takes a callback function that will be called each time the jobs are checked (I use this for additional logging)

    There are some things that I want to add to firebase-cron and it's documentation but haven't gotten to them yet. I've been using it in production environments for a while now and haven't had any problems with firebase-cron itself... just user errors in my queue logic ;)

    Also, I've been using the new Firebase Cloud Functions and they're great. I may add a feature to be able to trigger a cloud function instead of using firebase-queue. This probably won't be necessary once their cron service is running.

提交回复
热议问题