Triggering Cloud Functions for Firebase at Specific Times
Scheduling Cloud Functions for Firebase or triggering them on a specific time is a common requirement for various applications. While there was no built-in feature initially, several options are now available for this purpose.
Scheduled Functions (Blaze Plan Only)
In April 2019, a new feature was introduced that allows scheduling Cloud Functions directly through Firebase. This feature requires a project on the Blaze plan. To use it:
Text Syntax:
export scheduledFunctionPlainEnglish = functions.pubsub.schedule('every 5 minutes').onRun((context) => { console.log('This will be run every 5 minutes!'); })
Cron Table Format:
export scheduledFunctionCrontab = functions.pubsub.schedule('5 11 * * *').timeZone('UTC').onRun((context) => { console.log('This will be run every day at 11:05 AM UTC!'); });
Cloud Tasks for Delayed Function Invocations
If you want to schedule a single invocation of a Cloud Function on a delay from within another trigger, you can use Cloud Tasks. This option is useful for scenarios where you need to defer the execution of a function.
External Services for Periodic HTTP Triggers
For projects on a free plan or for more complex scheduling requirements, you can use external services to trigger a HTTP function periodically. These services include:
Please note that using cron-job.org allows anyone to call your function without authorization, so it's recommended to implement abuse protection in your code.
The above is the detailed content of How Can I Schedule Cloud Functions for Firebase to Run at Specific Times?. For more information, please follow other related articles on the PHP Chinese website!