芹菜不排队到远程代理,而是将任务添加到本地主机

Celery not queuing to a remote broker, adding tasks to a localhost instead

我的问题与此相同Celery not queuing tasks to broker on remote server, adds tasks to localhost instead,但答案对我不起作用。

我的celery.py

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

app = Celery('project', broker='amqp://<user>:<user_pass>@remoteserver:5672/<vhost>', backend='amqp')
# app = Celery('project')
# Using a string here means the worker don'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')

# Load task modules from all registered Django app configs.
app.autodiscover_tasks()


@app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))

当我运行:

$ celery -A worker -l info

我收到以下输出:

 -------------- celery@paulo-Inspiron-3420 v4.2.1 (windowlicker)
---- **** ----- 
--- * ***  * -- Linux-4.15.0-36-generic-x86_64-with-Ubuntu-18.04-bionic       2018-10-30 13:44:07
-- * - **** --- 
- ** ---------- [config]
- ** ---------- .> app:         mycelery:0x7ff88ca043c8
- ** ---------- .> transport:   amqp://<user>:**@<remote_ip>:5672/<vhost>
- ** ---------- .> results:     disabled://
- *** --- * --- .> concurrency: 4 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** ----- 
 -------------- [queues]
            .> celery           exchange=celery(direct) key=celery

我尝试停止 rabbitmq 服务器并将其卸载,但 celery 一直在排队到本地主机。

有人可以帮忙吗?

您需要在与 celery.py 文件相同的目录中的 __init__.py 文件中添加如下内容:

from __future__ import absolute_import, unicode_literals
from .celery import app as celery_app

__all__ = ('celery_app',)

此外,请确保您从项目的 virtualenv 内部启动工作进程。