【问题标题】:Why flower's HTTP API get task info not work?为什么花的 HTTP API 获取任务信息不起作用?
【发布时间】:2018-07-05 01:27:26
【问题描述】:

我有一个正在工作的芹菜花项目。 现在我想要一些使用花 http api 的 celery 任务详细信息,但是当我在 http://localhost:5555/api/task/info/task_id 上的花 http api 发出请求时,它返回 500 错误?

花页中的一切都很好。

在使用requests获取http api时,发生了一些错误!

所有步骤都遵循Flower's documentation。花日志如下:

【问题讨论】:

    标签: celery flower


    【解决方案1】:

    对于花0.9.2,它尝试将task._fields的每个属性放入响应中:

    def get(self, taskid):
        ...
        response = {}
        for name in task._fields:
            if name not in ['uuid', 'worker']:
                response[name] = getattr(task, name, None)
        response['task-id'] = task.uuid
        if task.worker is not None:
            response['worker'] = task.worker.hostname
        self.write(response)
    

    原来task._fields中有Task对象,比如parentroot

    class Task(object):
        ...
        _fields = (
            ...
            'clock', 'client', 'root', 'root_id', 'parent', 'parent_id', 'children',
        )
    

    在 celery 中,这些字段具有特定的序列化处理程序:

    self._serializer_handlers = {
        'children': self._serializable_children,
        'root': self._serializable_root,
        'parent': self._serializable_parent,
    }
    

    在花中,它只是将它传递给self.write,它不知道如何序列化这些对象。

    我认为它已在花 1.0.0 中修复:

    def get(self, taskid):
        ...
        response = task.as_dict()
        if task.worker is not None:
            response['worker'] = task.worker.hostname
    
        self.write(response)
    

    as_dict 函数中,如果可用或使用默认键,则将序列化委托给 celery:

    def as_dict(task):
        # as_dict is new in Celery 3.1.7
        if hasattr(Task, 'as_dict'):
            return task.as_dict()
        # old version
        else:
            return task.info(fields=task._defaults.keys())
    

    版本 1.0.0 仍在开发中,但您可以通过运行 pip install git+https://github.com/mher/flower.git 从 git repo 安装它。

    【讨论】:

    • 谢谢,已经解决了。 Conda 的版本不是最新的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-08-03
    • 2021-08-17
    • 1970-01-01
    • 2021-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多