Skip to content

.delay() shoud be async  #9

@alex-kowalczyk

Description

@alex-kowalczyk

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions