芹菜和Heroku上的Cloudamqp抛出错误:[Errno 111]连接被拒绝

时间:2014-03-31 15:59:11

标签: django heroku celery cloudamqp

我有Django应用程序,它使用Celery进行异步任务。另外,我在本地使用RabbitMQ,但在Heroku上我正在尝试设置CloudAMQP插件。应用程序启动没有任何错误,但发送到Celery的任何任务都失败并显示错误: [Errno 111]连接被拒绝以下是heroku日志在开始时的样子:

heroku[celery.1]: Process exited with status 0
heroku[celery.1]: Starting process with command `celery worker -A mysite -l info --beat`
heroku[web.1]: Starting process with command `gunicorn mysite.wsgi`
heroku[celery.1]: State changed from starting to up
app[web.1]: 2014-03-31 15:10:13 [2] [INFO] Starting gunicorn 18.0
app[web.1]: 2014-03-31 15:10:13 [2] [INFO] Listening at: http://0.0.0.0:51389 (2)
app[web.1]: 2014-03-31 15:10:13 [2] [INFO] Using worker: sync
app[web.1]: 2014-03-31 15:10:13 [7] [INFO] Booting worker with pid: 7
heroku[web.1]: State changed from starting to up
app[celery.1]: - ** ---------- .> transport:   amqp://xxx@tiger.cloudamqp.com:5672/xxx
app[celery.1]: - ** ---------- .> results:     amqp
app[celery.1]:  -------------- celery@124124-23a8-sdf3-bd25-basdjah v3.1.10 (Cipater)
app[celery.1]: --- * ***  * -- Linux-3.8.11-ec2-x86_64-with-debian-squeeze-sid
app[celery.1]: - ** ---------- .> app:         mysite:0x2846324123
app[celery.1]:   . tasks.add
app[celery.1]: [tasks]
app[celery.1]: -- ******* ---- 
app[celery.1]:   . mysite.celery.debug_task
app[celery.1]: - *** --- * --- .> concurrency: 4 (prefork)
app[celery.1]:   . tasks.a
app[celery.1]:  -------------- .> celery           exchange=celery(direct) key=celery
app[celery.1]:   . tasks.k
app[celery.1]: --- ***** ----- [queues]
app[celery.1]: [2014-03-31 17:10:16,332: INFO/Beat] beat: Starting...
app[celery.1]: [2014-03-31 17:10:16,592: INFO/MainProcess] Connected to amqp://xxx@tiger.cloudamqp.com:5672/xxx
app[celery.1]: [2014-03-31 17:10:16,737: INFO/MainProcess] mingle: searching for neighbors
app[celery.1]: [2014-03-31 17:10:17,785: INFO/MainProcess] mingle: all alone
app[celery.1]: [2014-03-31 17:10:17,929: WARNING/MainProcess] /app/.heroku/python/lib/python2.7/site-packages/celery/fixups/django.py:233: UserWarning: Using settings.DEBUG leads to a memory leak, never use this setting in production environments!
app[celery.1]:   warnings.warn('Using settings.DEBUG leads to a memory leak, never '
app[celery.1]: /app/.heroku/python/lib/python2.7/site-packages/celery/fixups/django.py:233: UserWarning: Using settings.DEBUG leads to a memory leak, never use this setting in production environments!
app[celery.1]:   warnings.warn('Using settings.DEBUG leads to a memory leak, never '
WARNING/MainProcess] celery@124124-23a8-sdf3-bd25-basdjah ready.

我有一个简单的任务,在调用它时失败了:

@app.task(name='tasks.add')
def add(x, y):
    return x * y

这是heroku日志:

Internal Server Error: /configurator/perf_test
app[web.1]: Traceback (most recent call last):
app[web.1]:     response = wrapped_callback(request, *callback_args, **callback_kwargs)
app[web.1]:   File "/app/configurator/views.py", line 58, in perf_test
[web.1]:     job_id = tasks.add.delay(2,3)
[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/celery/app/task.py", line 453, in delay
[web.1]:     return self.apply_async(args, kwargs)
app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/celery/app/amqp.py", line 302, in publish_task
app[web.1]:     **kwargs
app[web.1]:     reply_to=reply_to or self.oid, **options
app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py", line 114, in get_response
app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/kombu/connection.py", line 461, in _ensured
app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/celery/app/task.py", line 555, in apply_async
app[web.1]:     return self.connection
app[web.1]:     return fun(*args, **kwargs)
app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/kombu/connection.py", line 241, in connect
app[web.1]:     routing_key, mandatory, immediate, exchange, declare)
app[web.1]:     **dict(self._get_exec_options(), **options)
app[web.1]:     interval_start, interval_step, interval_max, callback)
app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/kombu/messaging.py", line 168, in publish
app[web.1]:     self._connection = self._establish_connection()
app[web.1]:     conn = self.transport.establish_connection()
app[web.1]:     interval_max)
app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/celery/app/base.py", line 323, in send_task
app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/kombu/utils/__init__.py", line 230, in retry_over_time
app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/kombu/connection.py", line 713, in _establish_connection
app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/kombu/connection.py", line 754, in connection
app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/amqp/connection.py", line 165, in __init__
app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/kombu/transport/pyamqp.py", line 111, in establish_connection
app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/kombu/connection.py", line 373, in ensure_connection
app[web.1]:     self.transport = create_transport(host, connect_timeout, ssl)
app[web.1]: error: [Errno 111] Connection refused
app[web.1]:     conn = self.Connection(**opts)
app[web.1]:     raise socket.error(last_err)
app[web.1]:     return TCPTransport(host, connect_timeout)

settings.py的一部分:

DEBUG = True
TEMPLATE_DEBUG = DEBUG
import djcelery
djcelery.setup_loader()
WSGI_APPLICATION = 'mysite.wsgi.application'

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'configurator',
    'django.contrib.admin',
    'kombu.transport.django',
    'djcelery',
)

CELERY_IMPORTS = ("tasks",)
import dj_database_url
DATABASES = {'default': dj_database_url.config()}

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
CELERY_ACCEPT_CONTENT = ['pickle', 'json', 'msgpack', 'yaml']
CELERY_RESULT_BACKEND = "amqp"
BROKER_POOL_LIMIT=1
BROKER_URL = os.environ.get('CLOUDAMQP_URL')

提前谢谢。

1 个答案:

答案 0 :(得分:0)

使用-w标志限制gunicorn工作者,使用-c限制芹菜工作者。使用免费的Little Lemur计划,您只能有3个并发连接。