A scheduled function in Firebase is a cloud function that runs automatically at set times or intervals, like a timer that triggers tasks without manual action.
Click to reveal answer
beginner
How do you define the timing for a scheduled function in Firebase?
You define the timing using a cron expression or a predefined schedule string that tells Firebase when to run the function, such as every hour or every day at midnight.
Click to reveal answer
beginner
Why use scheduled functions instead of manual triggers?
Scheduled functions automate repetitive tasks, save time, and ensure tasks run reliably at specific times without needing someone to start them manually.
Click to reveal answer
intermediate
What Firebase package do you import to create scheduled functions?
You import 'firebase-functions' and use the 'functions.pubsub.schedule()' method to create scheduled functions.
Click to reveal answer
intermediate
Give an example of a cron expression to run a function every day at 3 AM.
The cron expression is '0 3 * * *', which means at minute 0, hour 3, every day, every month, every weekday.
Click to reveal answer
What does a scheduled function in Firebase do?
ARuns when a file is uploaded
BRuns only when a user clicks a button
CRuns only during development
DRuns automatically at set times
✗ Incorrect
Scheduled functions run automatically based on a set schedule, not triggered by user actions or file uploads.
Which method is used to schedule a function in Firebase?
Afunctions.storage.object()
Bfunctions.pubsub.schedule()
Cfunctions.auth.user()
Dfunctions.database.ref()
✗ Incorrect
The 'pubsub.schedule()' method is used to create scheduled functions in Firebase.
What does the cron expression '0 0 * * *' mean?
ARun every day at midnight
BRun every hour
CRun every minute
DRun every Sunday
✗ Incorrect
'0 0 * * *' means run at minute 0, hour 0 every day, which is midnight daily.
Why are scheduled functions useful?
AThey require user input to run
BThey only run during app deployment
CThey automate tasks without manual start
DThey replace database triggers
✗ Incorrect
Scheduled functions automate tasks by running on a timer, no manual input needed.
Which Firebase package do you need to import to create scheduled functions?
Afirebase-functions
Bfirebase-auth
Cfirebase-storage
Dfirebase-database
✗ Incorrect
'firebase-functions' package provides the tools to create scheduled cloud functions.
Explain how to create a scheduled function in Firebase and set it to run every hour.
Think about the cron syntax and the Firebase method to schedule.
You got /4 concepts.
Describe the benefits of using scheduled functions in cloud infrastructure.
Consider why timers help in daily operations.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of Firebase Scheduled Functions?
easy
A. To run code automatically at specific times without manual intervention
B. To store user data securely in the cloud
C. To create real-time chat applications
D. To manage user authentication and login
Solution
Step 1: Understand the role of scheduled functions
Scheduled functions are designed to run tasks automatically at set times without needing a user to start them.
Step 2: Compare with other Firebase features
Other options like storing data, chat apps, or authentication are handled by different Firebase services, not scheduled functions.
Final Answer:
To run code automatically at specific times without manual intervention -> Option A
Quick Check:
Scheduled functions = automatic timed code run [OK]
Hint: Scheduled functions run code on a timer, no clicks needed [OK]
Common Mistakes:
Confusing scheduled functions with database storage
Thinking scheduled functions handle user login
Assuming scheduled functions manage real-time data
2. Which of the following is the correct way to schedule a Firebase function to run every day at midnight using cron syntax?
easy
A. functions.pubsub.schedule('every day 00:00').onRun(...)
B. functions.pubsub.schedule('daily at midnight').onRun(...)
C. functions.pubsub.schedule('0 0 * * *').onRun(...)
D. functions.pubsub.schedule('midnight every day').onRun(...)
Solution
Step 1: Identify correct cron syntax for midnight daily
The cron expression '0 0 * * *' means minute 0, hour 0, every day, which is midnight daily.
Step 2: Match with Firebase schedule method
Firebase uses cron syntax strings like '0 0 * * *' in schedule() to set times precisely.
Final Answer:
functions.pubsub.schedule('0 0 * * *').onRun(...) -> Option C
Quick Check:
Cron '0 0 * * *' = midnight daily [OK]
Hint: Cron '0 0 * * *' means every day at midnight [OK]
Common Mistakes:
Using natural language instead of cron syntax
Incorrect cron format like 'every day 00:00'
Misplacing hour and minute values in cron
3. Given the following Firebase scheduled function code, what will it log when triggered?
A. The schedule string 'every 60 minutes' is invalid; should use 'every 1 hour' or cron syntax
B. The function must return a promise or null, missing return statement
C. The function name 'cleanup' is reserved and cannot be used
D. The schedule method requires a timezone parameter
Solution
Step 1: Check the schedule string validity
Firebase does not recognize 'every 60 minutes'; it supports 'every 1 hour' or cron expressions.
Step 2: Review other code parts
Returning a promise or null is recommended but not mandatory here; function name and timezone are not issues.
Final Answer:
The schedule string 'every 60 minutes' is invalid; should use 'every 1 hour' or cron syntax -> Option A
Quick Check:
Invalid schedule string = error [OK]
Hint: Use 'every 1 hour' not 'every 60 minutes' in schedule [OK]
Common Mistakes:
Using unsupported time phrases in schedule
Forgetting to return null or a promise
Assuming timezone is always required
5. You want to create a Firebase scheduled function that runs every Monday at 9:30 AM in New York time to send weekly reports. Which is the correct way to configure this function?
hard
A. functions.pubsub.schedule('every Monday 9:30').timeZone('America/New_York').onRun(...)
B. functions.pubsub.schedule('30 9 * * 1').timeZone('America/New_York').onRun(...)
C. functions.pubsub.schedule('0 9 * * 1').timeZone('EST').onRun(...)
D. functions.pubsub.schedule('30 9 * * 1').onRun(...)
Solution
Step 1: Use correct cron syntax for Monday 9:30 AM
The cron '30 9 * * 1' means minute 30, hour 9, every Monday (day 1).
Step 2: Set proper timezone for New York
Use the full IANA timezone string 'America/New_York' to handle daylight savings correctly.
Step 3: Verify other options
functions.pubsub.schedule('every Monday 9:30').timeZone('America/New_York').onRun(...) uses invalid schedule string; functions.pubsub.schedule('0 9 * * 1').timeZone('EST').onRun(...) uses 'EST' which is not a valid timezone identifier; functions.pubsub.schedule('30 9 * * 1').onRun(...) misses timezone setting.
Final Answer:
functions.pubsub.schedule('30 9 * * 1').timeZone('America/New_York').onRun(...) -> Option B