Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

the right way to return a response from firebase a Google Cloud Pub/Sub Triggers

I am trying to implement a firebase cron function from the functions-cron example

var functions = require('firebase-functions');

exports.hourly_job =
  functions.pubsub.topic('hourly-tick').onPublish((event) => {
    console.log("This job is ran every hour!")
});

and I just wants to know the right way to return 200 response as it s requested because I have the error log

Function returned undefined, expected Promise or value

since I dont have access to response object as in the HTTP triggers I just want to know if returning the 200 int value is sufficient ?

the doc states the following

Cron retries

If a cron job's request handler returns a status code that is not in the range 200–299 (inclusive) App Engine considers the job to have failed. By default, failed jobs are not retried. You can cause failed jobs to be retried by including a retry_parameters block in your configuration file.

like image 580
Marcos DaSilva Avatar asked Jan 27 '26 04:01

Marcos DaSilva


1 Answers

Pub/Sub triggers don't have a response. They simply receive messages as they appear. Only HTTPS triggers require a response sent to the client.

If you want to prevent that warning message, simply return null at the end of your function as you show it now. The actual return value is meaningless. If you're doing async work in the function, you should instead return a promise that's resolved when the work is complete.

like image 60
Doug Stevenson Avatar answered Jan 28 '26 18:01

Doug Stevenson