Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firestore: Async callbacks on_snapshot #3

Closed
NixBiks opened this issue Jan 28, 2020 · 6 comments
Closed

Firestore: Async callbacks on_snapshot #3

NixBiks opened this issue Jan 28, 2020 · 6 comments
Assignees
Labels
api: firestore Issues related to the googleapis/python-firestore API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@NixBiks
Copy link

NixBiks commented Jan 28, 2020

Problem

I am writing a bunch of python applications that listens to news on firestore using on_snapshot. Some of the callbacks have IO-bound tasks which blocks other callbacks and builds up a queue.

Here's a mockup demonstrating the issue

from google.cloud.firestore import Client
import time

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

    # mock IO-bound task
    time.sleep(1)
    print("Finished handling the updates")

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

while True:
    pass

Solution

I'm no expert on this matter but I'm guessing that async is the right path. It would be great if something like this would be possible

from google.cloud.firestore import Client
import asyncio

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

    # mock IO-bound task
    await asyncio.sleep(1)
    print("Finished handling the updates")

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

while True:
    pass

** Alternatives **

I've also considered using multithreading but I think async is much preferred.

@BenWhitehead
Copy link
Collaborator

@crwilcox I'll have to defer to your knowledge here

@BenWhitehead BenWhitehead removed their assignment Jan 30, 2020
@crwilcox crwilcox transferred this issue from googleapis/google-cloud-python Jan 31, 2020
@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/python-firestore API. label Jan 31, 2020
@yoshi-automation yoshi-automation added 🚨 This issue needs some love. triage me I really want to be triaged. labels Feb 3, 2020
@jkwlui jkwlui added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed 🚨 This issue needs some love. triage me I really want to be triaged. labels Feb 4, 2020
@MaticConradi
Copy link

MaticConradi commented May 10, 2020

I'm looking forward to this. I'm using multiple snapshot listeners in my project where basically all operations are asynchronous, so this would be really handy

@therefromhere
Copy link

With google-api-core beginning to add AsyncIO support since version 1.18.0 it'd be awesome to get async support for firestore.

@NixBiks
Copy link
Author

NixBiks commented Dec 1, 2020

Any updates on this? I've noted that you've added some async and await code in v2 but I can't find anything about in the docs?

@crwilcox
Copy link
Contributor

crwilcox commented Dec 1, 2020

@mr-bjerre we did add a good amount of async surface to this client, though I don't believe we have made any changes to watch specifically. async_client, async_batch, async_collection, etc. Alongside their sync counter parts client, batch, async_collection, etc.

We had made #131 to track adding async watch support.

@craiglabenz
Copy link
Contributor

Closing this as a duplicate of #131 (even though this came first).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the googleapis/python-firestore API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

8 participants