Hey guys I am trying to deploy a scheduled Firebase function using the gen2 onSchedule function. I do not know anything about Google Cloud cloud scheduler. I built the function using an HTTP trigger function onRun() and it worked - the function just uses openai to generate a voice message and then sends a push notification to the user.
I then tried to convert it to a scheduled function every 10 minutes so it can send a daily voice message to each user at their specified time. The problem is I keep getting this error when running npm run deploy:
"""
Could not create or update Cloud Run service generatedailyvoicemessages, Container Healthcheck failed. Revision 'generatedailyvoicemessages-00001-deh' is not ready and cannot serve traffic. The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable. Logs for this revision might contain more information.
"""
In the docs online I cannot see anywhere where it asks to specify the port or set anything like that up (i thought firebase SDK would just take care of all this stuff). https://firebase.google.com/docs/functions/schedule-functions?gen=2nd
The skeleton code for my function is below and the only environment variable I am using is "OPENAI_API_KEY =" so this should be affecting anything.
// imports
// firebase imports
const admin = require("firebase-admin");
const {onSchedule} = require("firebase-functions/v2/scheduler");
const functions = require("firebase-functions");
// 3rd party imports
const moment = require("moment-timezone");
const dotenv = require("dotenv");
// helper function imports
admin.initializeApp();
const db = admin.firestore();
const storage = admin.storage();
dotenv.config();
// for testing
// exports.generateDailyVoiceMessages = v2.https.onRequest(async (request, response) => {
exports.generateDailyVoiceMessages = onSchedule("every 10 minutes", async (_) => {
// function logic
return null;
});
The full error is below:
```
โ functions git:(main) npm run deploy
> deploy
> firebase deploy --only functions
=== Deploying to 'goal-getter-fn2csm'...
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> lint
> eslint .
โ functions: Finished running predeploy script.
i functions: preparing codebase default for deployment
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
i artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...
โ functions: required API cloudfunctions.googleapis.com is enabled
โ artifactregistry: required API artifactregistry.googleapis.com is enabled
โ functions: required API cloudbuild.googleapis.com is enabled
โ functions: package.json indicates an outdated version of firebase-functions. Please upgrade using npm install --save firebase-functions@latest in your functions directory.
i functions: Loading and analyzing source code for codebase default to determine what to deploy
Serving at port 8752
i functions: Loaded environment variables from .env.
i functions: preparing functions directory for uploading...
i functions: packaged /Users/grahamherdman/Documents/goal-getter/goalgetter-codebase/goalgetter-firebase/functions (79.01 KB) for uploading
i functions: ensuring required API cloudscheduler.googleapis.com is enabled...
โ functions: required API cloudscheduler.googleapis.com is enabled
i functions: ensuring required API run.googleapis.com is enabled...
i functions: ensuring required API eventarc.googleapis.com is enabled...
i functions: ensuring required API pubsub.googleapis.com is enabled...
i functions: ensuring required API storage.googleapis.com is enabled...
โ functions: required API storage.googleapis.com is enabled
โ functions: required API run.googleapis.com is enabled
โ functions: required API pubsub.googleapis.com is enabled
โ functions: required API eventarc.googleapis.com is enabled
i functions: generating the service identity for pubsub.googleapis.com...
i functions: generating the service identity for eventarc.googleapis.com...
โ functions: functions folder uploaded successfully
i functions: creating Node.js 18 (2nd Gen) function generateDailyVoiceMessages(us-central1)...
Could not create or update Cloud Run service generatedailyvoicemessages, Container Healthcheck failed. Revision 'generatedailyvoicemessages-00001-deh' is not ready and cannot serve traffic. The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable. Logs for this revision might contain more information.
Logs URL: https://console.cloud.google.com/logs/viewer?project=goal-getter-fn2csm&resource=cloud_run_revision/service_name/generatedailyvoicemessages/revision_name/generatedailyvoicemessages-00001-deh&advancedFilter=resource.type%3D%22cloud_run_revision%22%0Aresource.labels.service_name%3D%22generatedailyvoicemessages%22%0Aresource.labels.revision_name%3D%22generatedailyvoicemessages-00001-deh%22
For more troubleshooting guidance, see https://cloud.google.com/run/docs/troubleshooting#container-failed-to-start
Functions deploy had errors with the following functions:
generateDailyVoiceMessages(us-central1)
i functions: cleaning up build files...
โ functions: Unhandled error cleaning up build images. This could result in a small monthly bill if not corrected. You can attempt to delete these images by redeploying or you can delete them manually at https://console.cloud.google.com/gcr/images/goal-getter-fn2csm/us/gcf
Error: There was an error deploying functions
```
Please can someone provide assistance on this one?