【发布时间】:2022-01-13 01:01:56
【问题描述】:
我刚刚进入我的 Django 项目中的 Celery 链。我有以下功能:
def orchestrate_tasks_for_account(account_id):
# Get the account, set status to 'SYNC' until the chain is complete
account = Account.objects.get(id=account_id)
account.status = "SYNC"
account.save()
chain = task1.s(account_id) | task2.s() | task3.s()
chain()
# if any of the tasks in the chain failed, set account.status = 'ERROR'
# else set the account.status = 'OK'
链按预期工作,但我不确定如何从链中获取反馈并根据结果更新帐户
换句话说,如果链中的任何任务失败,我想将帐户状态设置为'ERROR',否则我想将帐户状态设置为'OK'
我对 Celery 文档关于如何使用 if/else 处理错误感到困惑,就像我在上面最后两行中评论的那样。
有人有这方面的经验吗?
【问题讨论】:
标签: celery celery-task