Celery错误回调未被调用

时间:2016-11-16 16:24:27

标签: python celery

我有一个芹菜应用程序,我必须执行任务 A ,然后执行一组任务 B ;如果一切顺利,最后一个任务 C 。 任务 A B 可能会引发异常。

我已按照Celery documentation中的代码(他们使用on_chord_error),并且没有为任务组 B 调用回调,除非

以下是我的代码的简化示例:

@celery.task()
def task_a(throw_exc=False):
    print('first task')
    if throw_exc: raise KeyError

@celery.task()
def task_b(i):
    print('intermediate task %d' % i)
    if i == 2: raise ValueError

@celery.task()
def task_c(*args):
    print('Final task with args %s' % args)

@celery.task()
def error_task3(request, exc, traceback):
    print('An error occured')
    print(exc)

@celery.task()
def error_task1(*args):
    print('An error occured')
    print(exc)

def call_tasks(throw_exc):
    first = task_a.si(throw_exc).on_error(error_task3.s()) # WORKING
    g = group(task_b.si(i) for i in range(5))
    final = task_c.s().on_error(error_task3.s()) # NOT WORKING
    final2 = task_c.s().on_error(error_task1.s()) # WORKING

    (first | g | final).delay()  # Callback never called
    (first | g | final2).delay() # Callback called with the task id as a string

我误解了文档,还是错误?

0 个答案:

没有答案