How to trigger cloud function based on date stored in cloud firestore?

1k views Asked by At

I'm building an app that allows users to schedule social media posts. The date (and time) when the post is supposed to go live is stored (along with the content of the post) in a cloud firestore document. Is there a way to trigger the cloud function based on the date set by the user?

1

There are 1 answers

0
Frank van Puffelen On BEST ANSWER

The built-in type to trigger scheduled functions sets the schedule at deploy time. There is no built-in trigger type to trigger at a specific dynamic time. But you can use Cloud Scheduler to dynamically schedule a callback to a Cloud Function.

Doug Stevenson wrote a good blog post about that, so I recommend checking that out: How to schedule a Cloud Function to run in the future with Cloud Tasks (to build a Firestore document TTL).

There is nowadays also a built-in trigger type for this: enqueue functions with Cloud Tasks