Home > Back-end >  Scheduled Firebase Functions
Scheduled Firebase Functions

Time:09-18

I want to create some scheduled cloud functions using the syntax below to define the schedule within the source code of the function:

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

I know that according to the documentation, this cloud function automatically creates a pub/sub topic to trigger the function according to the defined schedule. The docs warn against manually editing the pub/sub topic in the GCP console, as it could break the scheduling.

What they don't mention is how one goes about removing a pub/sub topic of a function that you want to delete or update.

Do I need to delete the function entirely and re-deploy it with the updated schedule details? Will that automatically delete the associated pub/sub topic as well? What if I just re-deploy the same function with different schedule details?

CodePudding user response:

What if I just re-deploy the same function with different schedule details?

The schedule will be updated in Pub/Sub as well.

Will deleting the function automatically delete the associated pub/sub topic as well?

Yes, the topic will be deleted when a function is deleted using the CLI with firebase functions:delete functionName command or the Firebase console.

When you deploy a Pub/Sub triggered function from GCP, you are asked to select/create a topic and similarly you'll have to delete it yourself then. GCP won't delete the topic and it might be better just in case you are using the same trigger somewhere else.

  • Related