Is there a way to receive a notification as soon as a certain task with a certain task id is successful or fails using Celery for Python?

点点圈 提交于 2020-01-15 20:00:55

问题


I want to know if there is a way to monitor whether or not a task completes or fails as soon as it does using python celery. I have an event I want to fire up based on the results of a certain task.


回答1:


You can run your task as a celery @shared_task with a try except block inside:

@shared_task
def my_task(input1, input2, ...):
    Setting up...
    try:
        Do stuff
        fire_success_event() <- Your success event
    except Exception:
        The above stuff failed
        fire_fail_event() <- your fail event
        return 1 <- fail
    return 0 <- success

Good luck :)



来源:https://stackoverflow.com/questions/43273898/is-there-a-way-to-receive-a-notification-as-soon-as-a-certain-task-with-a-certai

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!