-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Awaitable task result #6603
Comments
we can try this in django-celery-results along with celery core as a POC first. but it is a part of a bigger design decision which we are planning for celery 6.0. additionally we can try to use an aio-libs in one of our result back end and see how things need to be done as experiments. |
this would be a very useful feature. |
As I wrote on stackoverflow, I currently use the following helper as a workaround: import asyncio
from asgiref.sync import sync_to_async
# Converts a Celery tasks to an async function
def task_to_async(task):
async def wrapper(*args, **kwargs):
delay = 0.1
async_result = await sync_to_async(task.delay)(*args, **kwargs)
while not async_result.ready():
await asyncio.sleep(delay)
delay = min(delay * 1.5, 2) # exponential backoff, max 2 seconds
return async_result.get()
return wrapper Like @shared_task
def get_answer():
sleep(10) # simulate long computation
return 42
result = await task_to_async(get_answer)() ...and as a decorator: @task_to_async
@shared_task
def get_answer():
sleep(10) # simulate long computation
return 42
result = await get_answer() Of course, this is not a perfect solution since it relies on polling, but it is a good workaround for calling tasks from Django async views until Celery officially provides a better solution. |
We're working on it. |
@thedrow can you explain more about what Jumpstarter is? |
https://github.com/celery/django-celery-results may be this one |
Checklist
for similar or identical feature requests.
for existing proposed implementations of this feature.
to find out if the if the same feature was already implemented in the
master branch.
in this issue (If there are none, check this box anyway).
Related Issues and Possible Duplicates
Related Issues
Possible Duplicates
Also related:
Brief Summary
Being able to
await
anAsyncResult
The goal is to offload CPU intensive tasks to dedicated workers and return a result to the client once the task is completed.
Design
Architectural Considerations
I don't know how to implement this feature, but it seems that this project does:
https://github.com/kai3341/celery-pool-asyncio
However, it's not compatible with Celery 5 (see kai3341/celery-pool-asyncio#29)
Proposed Behavior
Proposed UI/UX
In a Django 3.1 async view:
Diagrams
N/A
Alternatives
I've considered polling
AsyncResult.state
every second, but it's a very inelegant solution.The text was updated successfully, but these errors were encountered: