Stop the thread until the celery task runs out

I have a django web server and a form in which the user enters information. Every time the form information changes, I update the model in my database, and at some point, when something is checked, I will create a long-term task in the celery to get my results even before the user clicks on.

I am using Django Celery with RabbitMQ as a broker, and my question is what is the most suitable IN CASE way. The task is not finished yet, just to block the response flow in django until the task is state.SUCCESSFUL I tried to use the AsyncResult.get method , but it just fixes the stream for a long time and then gives me the result. IE It's not instant, does anyone have any ideas how to solve this?

+4
source share
2 answers

You can just wait until the result is there ready().

from time import sleep
result = some_task.apply_async(args=myargs)
while not result.ready():
    sleep(0.5)
result_output = result.get()

, wait(), . , .

result = some_task.apply_async(args=myargs)
result_output = result.wait(timeout=None, interval=0.5)
+2

- redis , session id, .

+1

All Articles