I integrated my project with celery in this way, inside views.py
after receving request from the user
def upload(request):
if "POST" == request.method:
# save the file
task_parse.delay()
# continue
and in tasks.py
from __future__ import absolute_import
from celery import shared_task
from uploadapp.main import aunit
@shared_task
def task_parse():
aunit()
return True
In short, the shared task will run a function aunit()
from a third python file located in uploadapp/
directory named main.py
.
Let's assume that aunit()
is a resource heavy process which takes time (like file parsing). As I integrated that with celery, It works totally asynchronously now which is good to me. So, the task start -> Celery process -> It finishes then celery set status to Finish. I can view that using flower
.
But what I want to do is that I want to notify the user who is using my app also through django UI that Your Task is done processing
as soon as Celery has finished processing at back-side and set status to SUCCESS.
Now, I know this is possible if :
1.) I constantly request the STATUS and see wheather it returns SUCCESS or not.
How do I do that via Celery. How can you query Celery Task status from your views.py
and notify user asynchronously with just celery's python module ?