使用Celery for Python,一旦具有特定任务ID的特定任务成功或失败,是否可以接收通知? [英] 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?

查看:40
本文介绍了使用Celery for Python,一旦具有特定任务ID的特定任务成功或失败,是否可以接收通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种方法可以立即使用python celery监视任务是否完成或失败.我有一个事件要根据特定任务的结果启动.

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.

推荐答案

您可以使用芹菜 @shared_task 来运行任务,并在其中使用 try 块,>

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

祝你好运:)

这篇关于使用Celery for Python,一旦具有特定任务ID的特定任务成功或失败,是否可以接收通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆