1

I am trying to schedule a function to run based on DateTime object field in my Firestore database.

Example, I have a collection of events in the Database and each event has a DateTime field (Start time) for the start of the event. The event also has a list of users that are subscribed to the event.

Is there a way to use Cloud Functions to notify the subscribed users that the event is about to start at the start time of the event or 5 or 10 mins before the event starts?

I am currently using Cloud Functions for notification and its working fine but that is based writes to specific portions of the database, not time event.

Thank you in advance.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Uma
  • 938
  • 1
  • 12
  • 28

1 Answers1

2

The only way to do this with a scheduled Cloud Function for this sort of work is to schedule it run periodically (every 1 minute is the most often), and query for documents that meet the criteria for when you want to send the notification at the moment that the function is currently running. This means you should be looking for documents where the time is in the 5-10 minute near future from the current time.

You can't use scheduled Cloud Functions to delay some work to happen later. But you can integrate with Cloud Tasks for that.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441