Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple returns on HTTP request in Firebase / Google Cloud Function

I have a Cloud Function that does some searching on my database. It's quite an expensive process that involves a lot of computing. Its goal is to find the best possible match. I have no way doing an early exit when a good match is found because a better one might be found later in the iteration cycle. So ideally I want to update the client regularly about the best matches so far. The issue is for a HTTP Cloud Function I can only return once. I was thinking of updating the results on the database somewhere and have the client listen in for changes, however, this may not be much faster since there will be some delay in that process too. So is there a way of returning multiples responses to a HTTP query in a Cloud Function? Is there a better solution to this I am not seeing?

Pseudo of what I need

def cloudFunction(someData):
    goodMatches = []
    for i in database:
        if (i == goodMatch):
            goodMatches.append(goodMatch)
            post new goodMatch to client
    return goodMatches
like image 353
Anters Bear Avatar asked Sep 16 '25 09:09

Anters Bear


1 Answers

An HTTP type function can only have one response, and it will be sent in its entirety. Cloud Functions does not support HTTP chunking or streaming of results. If you want to send progressive results, consider writing those into Cloud Firestore or Realtime Database at a unique location that's agreed upon between the client and the function.

like image 168
Doug Stevenson Avatar answered Sep 17 '25 22:09

Doug Stevenson