首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Celery未连接到redis服务器

Celery未连接到redis服务器
EN

Stack Overflow用户
提问于 2018-11-01 08:41:31
回答 6查看 8.6K关注 0票数 3

我有一个使用celery==4.2.1,redis==2.10.6,redis-server=4.0.9的django 2.0.5应用程序。当我启动celery worker时,我得到以下输出:

代码语言:javascript
复制
-------------- celery@octopus v4.2.1 (windowlicker)
---- **** ----- 
--- * ***  * -- Linux-4.18.16-surface-linux-surface-x86_64-with-Ubuntu-18.04-bionic 2018-10-31 17:33:50
-- * - **** --- 
- ** ---------- [config]
- ** ---------- .> app:         MemorabiliaJSON:0x7fd6c537b240
- ** ---------- .> transport:   amqp://guest:**@localhost:5672//
- ** ---------- .> results:     disabled://
- *** --- * --- .> concurrency: 4 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** ----- 
 -------------- [queues]
                .> celery           exchange=celery(direct) key=celery

但在我的django设置中,我有:

代码语言:javascript
复制
CELERY_BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TASK_SERIALIZER = 'json'
CELERY_IMPORTS = ('memorabilia.tasks',
                  'face_recognition.tasks',
                  )

我的celery.py看起来像这样:

代码语言:javascript
复制
# http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
from django.apps import apps
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'MemorabiliaJSON.settings.tsunami')

app = Celery('MemorabiliaJSON')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks(lambda: [n.name for n in apps.get_app_configs()])

相同的代码(通过我的git服务器共享)可以在我的开发机器上运行,尽管redis服务器更老一点-- v=2.8.4。开发机器是Ubunut 14.04,笔记本电脑是Ubuntu 18.04。工作,我的意思是这是我的开发机器上的芹菜输出:

代码语言:javascript
复制
 -------------- celery@tsunami v4.2.1 (windowlicker)
---- **** ----- 
--- * ***  * -- Linux-4.4.0-138-generic-x86_64-with-Ubuntu-14.04-trusty 2018-10-31 17:38:09
-- * - **** --- 
- ** ---------- [config]
- ** ---------- .> app:         MemorabiliaJSON:0x7f356e024c18
- ** ---------- .> transport:   redis://localhost:6379//
- ** ---------- .> results:     redis://localhost:6379/
- *** --- * --- .> concurrency: 8 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** ----- 
 -------------- [queues]
                .> celery           exchange=celery(direct) key=celery

除了celery.py中的配置文件之外,如何让celery读取django配置文件?

谢谢!

标记

EN

回答 6

Stack Overflow用户

发布于 2020-01-15 00:32:06

localhost更改为127.0.0.1解决了我的问题:

代码语言:javascript
复制
CELERY_BROKER_URL = 'redis://127.0.0.1:6379'
CELERY_RESULT_BACKEND = 'redis://127.0.0.1:6379'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TASK_SERIALIZER = 'json'
CELERY_STORE_ERRORS_EVEN_IF_IGNORED = True
票数 11
EN

Stack Overflow用户

发布于 2018-11-05 00:54:57

如果仔细查看来自celery@octopus的芹菜输出,您会发现它连接到一个amqp代理,而不是amqp://guest:**@localhost:5672//代理。这意味着您的octopus worker已配置为指向rabbitmq代理,而不是redis代理。为了纠正这个问题,您必须找到rabbitmq代理配置设置所在位置,并查看如何将其引入到芹菜中。因为broker_url告诉我们的是,不知何故,celery正在其他地方重新配置,或者服务器上正在应用其他设置。

票数 1
EN

Stack Overflow用户

发布于 2020-11-18 20:24:58

我正在使用celery & redis.Had来解决同样的问题,我像这样解决了它。

在you celery.py中转到行

代码语言:javascript
复制
 app.config_from_object("django.conf:settings", namespace="CELERY")

您只需删除namespace="CELERY“,最后您的代码应该是

代码语言:javascript
复制
     app.config_from_object("django.conf:settings")

这在我的情况下工作得很好。firstly it was like this

After update above settings

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53093757

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档