how to use firebase cloud function pubsub.schedule?
Solution 1
The announcement blog post points out that the version of the firebase-functions module also needs to be minimum 2.3.0. Run npm install firebase-functions@latest
in your functions folder to update it, then build and deploy again.
Solution 2
Here's the documentation https://firebase.google.com/docs/functions/schedule-functions
export const scheduledFunction = functions.pubsub.schedule('every 5 minutes')
.timeZone('Asia/Jakarta')
.onRun((context) => {
console.log('This will be run every 5 minutes!');
});
And you can set the timeZone as additional
![Sss Steve](https://lh4.googleusercontent.com/-SGg1xZ_ZvGM/AAAAAAAAAAI/AAAAAAAAAAA/ACHi3rerTgWbNuzNjIMYGATNAoKsmPKNqQ/mo/photo.jpg?sz=256)
Sss Steve
Updated on July 16, 2022Comments
-
Sss Steve almost 2 years
Today, there is new feature of Cloud Functions for Firebase which is running functions on a schedule. So I tried to test the sample code.
index.js file
exports.scheduledFunction = functions.pubsub.schedule(‘every 5 minutes’).onRun((context) => { console.log(‘This will be run every 5 minutes!’); });
But when I tried to deploy this, I got the following error message:
Error: Error occurred while parsing your function triggers. TypeError: functions.pubsub.schedule is not a function
My firebase tools version is
6.7
(updated today)What is the solution?
I checked the example git code in here (https://github.com/firebase/functions-samples/blob/master/delete-unused-accounts-cron/functions/index.js)
But it also cause the same error:
functions.pubsub.schedule is not a function
Can anyone help me with this problem?
const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(); exports.scheduledFunction = functions.pubsub.schedule('every 5 minutes').onRun((context) => { console.log('This will be run every 5 minutes!'); });