Celery 未提供主机名。恢复为默认“本地主机”

问题描述 投票:0回答:2

我的

/var/log/celery/w1.log

里有这个

我正在按照 Celery 的步骤这里

我的

celery.py

里有这个
from __future__ import absolute_import, unicode_literals

import os

from celery import Celery

# Set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sample.settings')

app = Celery('sample2',
            broker='amqp://',
            include=['sample2.tasks'])

# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
#   should have a `CELERY_` prefix. 
app.config_from_object('django.conf:settings', namespace='CELERY')

if __name__ == '__main__':
    app.start()

我可以做什么来解决这个问题?预先感谢。

django celery
2个回答
7
投票

完整文档位于此链接

您应该将以下行添加到 settings.py 附近的

__init__.py

from .celery import app as celery_app

__all__ = ['celery_app']

项目结构

- proj/
  - manage.py
  - proj/
    - __init__.py
    - settings.py
    - urls.py

0
投票

我仍然面临这个问题,任何人都可以帮助我添加文档链接中提到的配置,但仍然收到错误。也因为这个任务不会在 celery 中执行。此外,发送任务的 API 需要很长时间才能响应。这个问题间歇性出现

© www.soinside.com 2019 - 2024. All rights reserved.