如果条件不符合,我想明确地使任务失败。例如:
@app.task(bind=True, name="task.my_task", max_retries=2)
def my_task(self, filename):
result = get_result(filename)
if result is None:
self.update_state(task_id=self.request.id, state=states.FAILURE, meta="result is None")
raise Ignore()
return result
日志说“任务task.my_task [855c1cbc-e894-409f-af29-d70a35d86e34]忽略了”
然而,这不起作用。当我查看task.state
时,它处于PENDING状态。花说my_task state == STARTED
(它会卡在那里)。
我错过了什么吗?我如何通过芹菜任务失败?
答案 0 :(得分:-1)
要使任务失败,只需说出let_it_fail
@app.task(bind=True, name="task.my_task", max_retries=2)
def my_task(self, filename):
result = get_result(filename)
if result is None:
self.update_state(task_id=self.request.id, state=states.FAILURE, meta="result is None")
raise let_it_fail
return result