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

.delay() shoud be async #9

Open
alex-kowalczyk opened this issue Sep 30, 2023 · 2 comments
Open

.delay() shoud be async #9

alex-kowalczyk opened this issue Sep 30, 2023 · 2 comments

Comments

@alex-kowalczyk
Copy link

alex-kowalczyk commented Sep 30, 2023

The example in README shows how to queue a task with sync .delay() function, which is not a good idea in async handler.
We have remote IO there: usually low-latency, but no warranty. So .delay() blocks asyncio loop when called from async route.

README presents examples with async routes calling sync .delay() call example (e.g. "https://github.com/Adori/fastapi-cloud-tasks#local"). This might be misleading for a less experienced user.

Making .delay(...) async would allow to call

await make_dinner.delay(...)

or even

task = create_task(make_dinner.delay(...))
# make something else here in the meanwhile
# ...
# ensure the task was enqueued before the request has been finalized
await task  

Cloud Tasks library already provides async variant of the client for some time, and it works well:
https://cloud.google.com/python/docs/reference/cloudtasks/latest/google.cloud.tasks_v2.services.cloud_tasks.CloudTasksAsyncClient

@rushilsrivastava
Copy link

@yogeshdecodes would you be open to a PR with this functionality?

@yogeshdecodes
Copy link
Member

@rushilsrivastava thank you for your interest in contributing to the project and my apologies for the delayed response. I'd be open to reviewing a PR. Please go ahead and submit it, and I'll take a look as soon as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants