简体   繁体   中英

How to provide user constant notification about Celery's Task execution status?

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 ?

You need a real time mechanism. I would suggest Firebase. Update the Firebase real time DB field of user id with a boolean=True at the end of the celery task. Implement a javascript function to listen to Firebase database user_id object changes -> update the UI

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM