无法更新芹菜中的任务状态

时间:2018-05-03 10:29:05

标签: python celery

我正在使用带有redis和python 3的芹菜4.1.0来执行任务。

我正在运行这样的任务链:

def identifier():
    res = chain(
    authenticate.s(token),
    get_identifier.s(id_type, amount)
    ).apply_async()

    return jsonify({'task_id': res.id}), 202, {'Location': url_for('task_status', task_id=res.id)}

在我的get_identifier函数中,如果某些条件未满足,我会有以下其他声明:

@celery.task(bind=True)
def get_identifier(self, authentication, id_type, amount):
if:
    # some stuff
else:
    self.update_state(state=states.FAILURE, meta="result is None")
    return {'StatusCode': '403',
            'error_message': authentication['error_message'],
            'id_type': id_type,
            'identifier': items_list
            }

在另一个函数中,我正在检查这样的任务状态:

def task_status(task_id):
    task = get_identifier.AsyncResult(task_id)
    print(task.state)

任务状态始终为SUCCESS,但在代码输入FAILURE语句的情况下,我预计它为else

也许有人知道我在这里做错了什么。

0 个答案:

没有答案
相关问题