1

I have an application that listens to updates from a Firestore collection using google-cloud-firestore. For each update I need to do upload some data to an FTP server which takes time. Receiving a lot of data at the same time introduces delay that is not acceptable and I figure the answer is async callback (i.e. do not wait for my callback to end before continuing) but is that possible.

Imagine a script like this

from google.cloud.firestore import Client
import time


def callback(col_snapshot, changes, read_time):
    print("Received updates")

    # mock FTP upload
    time.sleep(1)
    print("Finished handling the updates")

Client().collection('news').on_snapshot(callback)

while True:
    pass

How can I modify that code so it doesn't queue each callback.

Update

I've created a feature request at google-cloud-firestore

mr.bjerre
  • 2,384
  • 2
  • 24
  • 37

1 Answers1

0

What you need to do is use one of the approaches mentioned in this SO question

My suggestion is using multiprocessing module in Python 3

Waelmas
  • 1,894
  • 1
  • 9
  • 19