Complete the code to schedule a function to run every 5 minutes.
exports.scheduledFunction = functions.pubsub.schedule('every 5 minutes').onRun((context) => { console.log('This function runs every 5 minutes'); return null; }); // Use [1] to import the Firebase functions module.
You need to import the Firebase functions module using require('firebase-functions') to use scheduled functions.
Complete the code to set the schedule expression for a daily function at midnight.
exports.dailyJob = functions.pubsub.schedule([1]).onRun((context) => { console.log('This runs daily at midnight'); return null; });
The schedule expression uses a cron syntax. '0 0 * * *' means every day at midnight.
Fix the error in the schedule expression to run every hour.
exports.hourlyJob = functions.pubsub.schedule([1]).onRun((context) => { console.log('Runs every hour'); return null; });
The correct cron expression for every hour at minute 0 is '0 * * * *'.
Fill both blanks to create a scheduled function that runs every Monday at 9 AM.
exports.weeklyJob = functions.pubsub.schedule([1]).timeZone([2]).onRun((context) => { console.log('Runs every Monday at 9 AM in specified timezone'); return null; });
The cron expression '0 9 * * 1' means 9 AM every Monday. The timezone 'America/New_York' sets the time zone for the schedule.
Fill all three blanks to create a scheduled function that runs every weekday at 8:30 AM in UTC timezone and logs a message.
exports.weekdayMorningJob = functions.pubsub.schedule([1]).timeZone([2]).onRun((context) => { console.log([3]); return null; });
The cron expression '30 8 * * 1-5' means 8:30 AM Monday to Friday. The timezone is set to 'UTC'. The console logs a clear message.
