简体   繁体   中英

Notification about task execution flask and celery

I am using celery and flask with a mongodb backend and broker.
I am trying to understand whats the best way to give a notification after running a group of synchronous task.

Both of the function have a decorator called @celery.task

def abc():  
    # do something

def fgh():  
    # do something

In order to run these programs, I am using (abc.s() | fgh.s()).delay() to run these tasks.

How do I signal the main program once these tasks have been executed completely?

Mb u can try flask-notification with Redis as Celery backend. Another way: check task state/status (something like status = celery.AsyncResult(str(task_id)).status ) with waiting intervals time.sleep(10) in cycle (for example, while True: ... ) and update progress bar on some page with jquery. After task completion (SUCCESS or FAILED status) you can show message with flash('your message') or set redirect. Hope thats help.

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