如果条件不满足,我想显式失败任务。例:
@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
时,它处于待处理状态。花说my_task state == STARTED
(它卡在那里(。
我错过了什么吗?如何使芹菜任务失败?
要使任务失败,只需说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