【问题标题】:How to find out what is missing in the Celery setup?如何找出 Celery 设置中缺少的内容?
【发布时间】:2015-02-09 17:49:09
【问题描述】:

对于我们的 Django 网站之一,我们需要运行 Celery。

我们在settings.py 中对 Celery 使用以下设置:

BROKER_URL = "redis://<ip address of the server>:6379/0"
CELERY_RESULT_BACKEND = "redis"
CELERY_REDIS_HOST = "<ip address of the server>"
CELERY_REDIS_PORT = 6379
CELERY_REDIS_DB = 0

Redis 运行正常:

$ redis-cli ping
PONG

我们用这个命令启动 Celery 服务器:

$ nohup python manage.py celeryd start

我们还有一个带有 Celery 任务的测试应用,但是当我们尝试使用它时,从未给出结果并且任务挂起:

$ python manage.py shell
>>> from celerytest.tasks import add
>>> result = add.delay(2, 2)
>>> result.ready() # returns True if the task has finished processing.
False
>>> result.result
None
>>> result.get()

我们正在使用 Django 1.3.7、Celery 3.0.9 和 djcelery 3.0.9。

我们如何找到导致 Celery 任务挂起的原因?

【问题讨论】:

    标签: django redis celery


    【解决方案1】:

    我认为您需要使用 -EB 选项运行 celeryd 命令。您也可以在前台运行它,以确保在将其发送到后台之前一切正常。

    例如

    python manage.py celeryd -EB -l debug
    

    我认为对于日志记录,您应该使用以下内容来实例化您的记录器:

    from celery.utils.log import get_task_logger
    
    log = get_task_logger(__name__)
    

    在您的设置中,您可能还需要检查此设置:

    CELERYD_HIJACK_ROOT_LOGGER = False
    

    这样我认为你应该能够看到日志。

    【讨论】:

    • 这些选项列出了可用的 Celery 任务,但在我的情况下这些任务仍然无法成功运行,并且没有任何类型的日志。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-15
    • 1970-01-01
    • 2018-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多