【问题标题】:How to find which database entry has been created using celery task id如何使用 celery 任务 ID 查找已创建的数据库条目
【发布时间】:2020-04-05 10:43:12
【问题描述】:

在我的一项 celery 任务中,我正在创建数据库条目。我知道如何读取我的 celery 任务的状态:

from celery.result import AsyncResult
res = AsyncResult("my-task-id")
res.ready()

但我想知道使用 celery 任务 ID 在特定任务上创建的确切数据库条目。我该怎么做?

提前致谢。

【问题讨论】:

标签: django celery django-celery


【解决方案1】:

当您插入新的数据库条目时,您将从查询中获得这些新插入的行的 ID。

Celery 任务可以返回“结果”。插入数据库条目后,只需返回那些 id / ids。

您现在可以通过任务 ID 检索任务的结果以获取数据库 ID。

【讨论】:

    猜你喜欢
    • 2020-06-03
    • 2016-12-30
    • 2013-01-07
    • 2013-02-18
    • 2017-04-03
    • 2021-09-27
    • 2014-01-28
    • 2023-02-12
    • 1970-01-01
    相关资源
    最近更新 更多