Google Cloud Scheduler using Firebase Functions

Google recently released a beta version of Google Cloud Scheduler . It makes much easier to schedule a task in firebase.


https://cloud.google.com/scheduler/docs/tut-pub-sub

You should enable APIs before proceed. Sorry, you have to have a billable account for continue.

https://cloud.google.com/scheduler/docs/quickstart

gcloud config list

 gcloud config set project <projectname>


gcloud components update

gcloud pubsub topics create cron-job . *** name of the pub sub cron-job

gcloud pubsub subscriptions create cron-sub --topic cron-job


After creating that , you have to go to shecdular

https://console.cloud.google.com/cloudscheduler

Select the project and create a scheduled task .

In target select pub sub and give the topic as the same name given in pub-sub generation above (cron-job ).


After creating the job you can define the code to execute in the firebase functions.
The code in the firebases function will be like below for pub sub job name "cron-job".


exports.cron_job =functions.pubsub.topic('cron-job').onPublish((event) => {
  console.log("This cron-job job is runnig every one 1 hour !");
return true;
})


Comments

Popular posts from this blog

ENOENT: no such file or directory, rename : node_modules/async

react-quill Integrate quill-image-resize-module