【问题标题】:Celery countdown error芹菜倒计时错误
【发布时间】:2013-03-14 13:12:56
【问题描述】:

我正在尝试为任务添加倒计时但没有成功。

这是我正在使用的代码

@celery.task
def check_st(key, t):
    device = Device.query.filter(Device.key == key).first()
    data = Data.query.filter(Data.dev_id == device.id).order_by(Data.timestamp.desc()).first()
    if(data.timestamp == t):
        return True

我是这样称呼它的

check_st.apply_async([key, data.timestamp], countdown=300)

取自完整的celery log

有什么想法吗?

编辑

使用倒计时测试一个简单的示例似乎可以正常工作。我想是我的项目布局导致问题与我运行 celery 的方式相结合。

所以我的布局是这样的

proj(app(__init__.py, views.py, models.py, tasks.py))

在我的 tasks.py 中,我导入这样的模块

from app.models import Device, Data

然后在我的views.py中我使用

导入任务
from app.tasks import check_st

我像这样在proj/ 目录中运行 celery

celery -A app.tasks worker -l info

使用此设置,其他所有任务都按预期工作,但是当我添加倒计时关键字时,我得到以下内容

Task app.tasks.check_st[deffd607-c6d4-41af-882c-e111736888ba] raised exception: TypeError("check_st() got an unexpected keyword argument 'countdown'",)

【问题讨论】:

  • first = datetime.datetime(year, month, 1, hour, minute)
  • 我的代码中没有这样的东西。
  • 您链接的日志正在执行一个不同的任务:Got task from broker: app.tasks.c heck_fence[5b28c53e-c842-4957-bed2-2d53ed0ec00a].
  • 它被task.eta 值抛出。
  • @MartijnPieters 此任务在 check_st 之前执行。如果我删除 check_st 执行,它不是导致问题的原因,它按预期工作。

标签: python celery


【解决方案1】:

问题终于解决了。解决方案来自于改变

celery -A app.tasks worker -l info

celery --workdir=proj/ -A app.tasks worker -l info

【讨论】: