gpt4 book ai didi

django 数据库作为 celery 代理给出连接被拒绝的错误

转载 作者:行者123 更新时间:2023-12-04 21:20:44 24 4
gpt4 key购买 nike

我正在尝试按照 http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html 上的说明进行操作使 celery 与 django 一起工作。

至于经纪人,我正在尝试按照 http://docs.celeryproject.org/en/latest/getting-started/brokers/django.html#broker-django 上的说明设置 django 数据库。 .

我可以成功启动一个 worker ,如下所示:

*****-MacBook-Air:celeryproject *****$ python manage.py celery worker -E --loglevel=info /Library/Python/2.7/site-packages/django_celery-3.0.9-py2.7.egg/djcelery/loaders.py:124:
UserWarning: Using settings.DEBUG leads to a memory leak, never use
this setting in production environments! warnings.warn("Using
settings.DEBUG leads to a memory leak, never " --------------
celery@*****-MacBook-Air.local v3.0.9 (Chiastic Slide)
---- **** -----
--- * *** * -- [Configuration]
-- * - **** --- . broker: django://localhost//
- ** ---------- . app: default:0x10b785fd0 (djcelery.loaders.DjangoLoader)
- ** ---------- . concurrency: 4 (processes)
- ** ---------- . events: ON
- ** ----------
- *** --- * --- [Queues]
-- ******* ---- . celery: exchange:celery(direct) binding:celery
--- ***** -----

[Tasks] . celeryapp.tasks.add

[2012-09-06 20:03:23,711: WARNING/MainProcess] celery@*****-MacBook-Air.local has started.
[2012-09-06 20:03:24,406: WARNING/PoolWorker-3] /Library/Python/2.7/site-
packages/django_celery-3.0.9-py2.7.egg/djcelery/loaders.py:124: UserWarning: Using settings.DEBUG leads to a memory leak, never use this setting in production environments!
warnings.warn("Using settings.DEBUG leads to a memory leak, never "
[2012-09-06 20:03:24,406: WARNING/PoolWorker-1] /Library/Python/2.7/site-packages/django_celery-3.0.9-py2.7.egg/djcelery/loaders.py:124: UserWarning: Using
settings.DEBUG leads to a memory leak, never use this setting in production environments!
warnings.warn("Using settings.DEBUG leads to a memory leak, never "
[2012-09-06 20:03:24,406: WARNING/PoolWorker-2] /Library/Python/2.7/site-packages/django_celery-3.0.9-py2.7.egg/djcelery/loaders.py:124: UserWarning: Using
settings.DEBUG leads to a memory leak, never use this setting in production environments!
warnings.warn("Using settings.DEBUG leads to a memory leak, never "

[2012-09-06 20:03:24,406:警告/PoolWorker-4]/Library/Python/2.7/site-
包/django_celery-3.0.9-py2.7.egg/djcelery/loaders.py:124: UserWarning: Using
settings.DEBUG 会导致内存泄漏,切勿在生产环境中使用此设置!
warnings.warn("使用 settings.DEBUG 会导致内存泄漏,永远不会"

但是,当我继续按照说明操作并调用在入门步骤中创建的添加任务时,我遇到了以下错误:
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53)   
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from celeryapp.tasks import add
>>> add.delay(2,2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/celery-3.0.9-py2.7.egg/celery/app/task.py", line 343, in delay
return self.apply_async(args, kwargs)
File "/Library/Python/2.7/site-packages/celery-3.0.9-py2.7.egg/celery/app/task.py", line 458, in apply_async
with app.producer_or_acquire(producer) as P:
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/Library/Python/2.7/site-packages/celery-3.0.9-py2.7.egg/celery/app/base.py", line 256, in producer_or_acquire
with self.amqp.producer_pool.acquire(block=True) as producer:
File "/Library/Python/2.7/site-packages/kombu-2.4.5-py2.7.egg/kombu/connection.py", line 712, in acquire
R = self.prepare(R)
File "/Library/Python/2.7/site-packages/kombu-2.4.5-py2.7.egg/kombu/pools.py", line 54, in prepare
p = p()
File "/Library/Python/2.7/site-packages/kombu-2.4.5-py2.7.egg/kombu/pools.py", line 45, in <lambda>
return lambda: self.create_producer()
File "/Library/Python/2.7/site-packages/kombu-2.4.5-py2.7.egg/kombu/pools.py", line 42, in create_producer
return self.Producer(self._acquire_connection())
File "/Library/Python/2.7/site-packages/celery-3.0.9-py2.7.egg/celery/app/amqp.py", line 160, in __init__
super(TaskProducer, self).__init__(channel, exchange, *args, **kwargs)
File "/Library/Python/2.7/site-packages/kombu-2.4.5-py2.7.egg/kombu/messaging.py", line 83, in __init__
self.revive(self.channel)
File "/Library/Python/2.7/site-packages/kombu-2.4.5-py2.7.egg/kombu/messaging.py", line 174, in revive
channel = self.channel = maybe_channel(channel)
File "/Library/Python/2.7/site-packages/kombu-2.4.5-py2.7.egg/kombu/connection.py", line 886, in maybe_channel
return channel.default_channel
File "/Library/Python/2.7/site-packages/kombu-2.4.5-py2.7.egg/kombu/connection.py", line 624, in default_channel
self.connection
File "/Library/Python/2.7/site-packages/kombu-2.4.5-py2.7.egg/kombu/connection.py", line 617, in connection
self._connection = self._establish_connection()
File "/Library/Python/2.7/site-packages/kombu-2.4.5-py2.7.egg/kombu/connection.py", line 576, in _establish_connection
conn = self.transport.establish_connection()
File "/Library/Python/2.7/site-packages/kombu-2.4.5-py2.7.egg/kombu/transport/amqplib.py", line 344, in establish_connection
connect_timeout=conninfo.connect_timeout)
File "/Library/Python/2.7/site-packages/kombu-2.4.5-py2.7.egg/kombu/transport/amqplib.py", line 154, in __init__
super(Connection, self).__init__(*args, **kwargs)
File "build/bdist.macosx-10.7-intel/egg/amqplib/client_0_8/connection.py", line 129, in __init__
File "build/bdist.macosx-10.7-intel/egg/amqplib/client_0_8/transport.py", line 281, in create_transport
File "build/bdist.macosx-10.7-intel/egg/amqplib/client_0_8/transport.py", line 85, in __init__
socket.error: [Errno 61] Connection refused

基本上,这个应用程序似乎无法与我的经纪人设置传输。

以下是我的 settings.py 的片段:
# Django settings for celeryproject project.
import djcelery
djcelery.setup_loader()

## Broker settings.
BROKER_URL= 'django://'
BROKER_BACKEND = "djkombu.transport.DatabaseTransport"

# List of modules to import when celery starts.
CELERY_IMPORTS = ("celeryapp.tasks", )

## Using the database to store task state and results.
#CELERY_RESULT_BACKEND = "database"
#CELERY_RESULT_DBURI = "sqlite:///mydatabase.db"

CELERY_ANNOTATIONS = {"tasks.add": {"rate_limit": "10/s"}}

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'celeryapp',
'djcelery',
#'djcelery.transport',
'kombu.transport.django',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)

任何的想法?

最佳答案

尝试添加

import djcelery
djcelery.setup_loader()

在您的代理和后端配置之后,同样根据 https://devcenter.heroku.com/articles/django#running-a-worker指南,mb 您需要更改 INSTALLED_APPS 顺序
'kombu.transport.django',
'djcelery'

关于django 数据库作为 celery 代理给出连接被拒绝的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12310575/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com