Celery和Rabbit在本地运行良好,但生产服务器上未收到任务

时间:2019-06-16 18:35:44

标签: django heroku rabbitmq celery

发送电子邮件作为后台任务在本地Rabbit Url上效果很好,但是似乎无法使用Rabbit:cloudAMQP将任务中继到Heroku上的Celery

Python3.6,Django2.2,Celery 4.3,Django-celery-mail 2。

我尝试在设置中添加BROKER_POOL_LIMIT = 1,但这并不能解决问题

在本地:

Settings.py

INSTALLED_APPS = [
...
djcelery_email,
...
]

CELERY_BROKER_URL = 'amqp://guest:guest@localhost:5672/'

EMAIL_BACKEND = 'djcelery_email.backends.CeleryEmailBackend'

celery.py

from __future__ import absolute_import
from django.conf import settings
import os
from celery import Celery

# setting DjanoSETTTINGS as default
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'my_app.settings')


app = Celery(broker=settings.CELERY_BROKER_URL)
app.config_from_object('django.conf.settings')
app.autodiscover_tasks(settings.INSTALLED_APPS)

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

celery -A vault worker -l info一起运行芹菜

工作良好,可以接收任务并执行。

在Heroku上:

但是;将heroku任务上的Broker URL设置为CELERY_BROKER_URL = os.environ['CLOUDAMQP_URL']永远不会收到。而是请求超时,

本地结果:

[2019-06-16 14:36:56,923: INFO/MainProcess] Connected to amqp://guest:**@127.0.0.1:5672//
[2019-06-16 14:36:56,950: INFO/MainProcess] mingle: searching for neighbors
[2019-06-16 14:36:58,017: INFO/MainProcess] mingle: all alone
[2019-06-16 14:36:58,100: INFO/MainProcess] celery@Pavilion ready.
[2019-06-16 14:36:58,103: INFO/MainProcess] Received task: djcelery_email_send_multiple[aa4ed64d-f91e-488a-a640-c35ea39a6646]  
[2019-06-16 14:37:02,306: INFO/ForkPoolWorker-8] Task djcelery_email_send_multiple[aa4ed64d-f91e-488a-a640-c35ea39a6646] succeeded in 4.09453737900003s: 1

Heroku上的结果:

2019-06-16T17:22:17.269761+00:00 app[worker.1]: [2019-06-16 17:22:17,264: INFO/MainProcess] Connected to amqp://abcdefhh:**@llama.rmq.cloudamqp.com:5276/abcdefhh
2019-06-16T17:22:17.317147+00:00 app[worker.1]: [2019-06-16 17:22:17,316: INFO/MainProcess] mingle: searching for neighbors
2019-06-16T17:22:18.383655+00:00 app[worker.1]: [2019-06-16 17:22:18,383: INFO/MainProcess] mingle: all alone
2019-06-16T17:22:18.449618+00:00 app[worker.1]: [2019-06-16 17:22:18,449: INFO/MainProcess] celery@eaa4cb0e-de01-4307-96cd-bdace12e418b ready.

2019-06-16T17:07:27.939719+00:00 app[web.1]: [2019-06-16 17:07:27 +0000] [4] [CRITICAL] WORKER TIMEOUT (pid:11)
2019-06-16T17:07:27.940783+00:00 app[web.1]: [2019-06-16 17:07:27 +0000] [11] [INFO] Worker exiting (pid: 11)
2019-06-16T17:07:28.069350+00:00 app[web.1]: [2019-06-16 17:07:28 +0000] [14] [INFO] Booting worker with pid: 14

0 个答案:

没有答案