工作,我有一个Django项目Django + RabbitMQ +芹菜。不从的观点
RabbitMQ的运行(命令行测试,其收到的消息)
芹菜运行并确认任务。
项目的简化树:
├── wha/core
│ ├── wha/core/__init__.py
│ ├── wha/core/celery.py
│ ├── wha/core/settings.py
│ ├── wha/core/urls.py
│ └── wha/core/wsgi.py
├── wha/factura
│ ├── wha/factura/__init__.py
│ ├── wha/factura/admin.py
│ ├── wha/factura/forms.py
│ ├── wha/factura/models.py
│ ├── wha/factura/urls.py
│ └── wha/factura/views.py
└── wha/manage.py
WHA /核心/ 初始化的.py
from __future__ import absolute_import
from .celery import app as celery_app
WHA /核心/ celery.py(as docs)
from __future__ import absolute_import
import os
from celery import Celery
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
from django.conf import settings
app = Celery('core')
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
WHA /core/settings.py
BROKER_URL = 'amqp://XXX:[email protected]:5672//'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_RESULT_BACKEND = "amqp"
CELERY_IMPORTS = ('factura.views')
WHA/factura/views.py
@task(name="factura.views.notify")
def notify(request, uid):
factura = get_object_or_404(Factura, pk=uid)
subject = '%s - Your domain' % factura.contrato.dominio.nombre.upper()
from_email = 'Mail Name <[email protected]>'
to = [factura.contrato.dominio.cliente.email]
[...]等等等等,发送电子邮件时,UID真是 “factura” ID。我认为没关系。
芹菜控制台输出(调试)
-------------- [email protected] v3.1.19 (Cipater)
---- **** -----
--- * *** * -- Darwin-15.2.0-x86_64-i386-64bit
-- * - **** ---
- ** ---------- [config]
- ** ---------- .> app: core:0x10c451fd0
- ** ---------- .> transport: amqp://hola:**@nnmbp:5672//
- ** ---------- .> results: amqp
- *** --- * --- .> concurrency: 4 (prefork)
-- ******* ----
--- ***** ----- [queues]
-------------- .> celery exchange=celery(direct) key=celery
[tasks]
. celery.backend_cleanup
. celery.chain
. celery.chord
. celery.chord_unlock
. celery.chunks
. celery.group
. celery.map
. celery.starmap
. factura.views.notify
URL调用视图:
http://localhost:8000/factura/notify/8
其中8是 “factura” ID,
编辑:
的不工作的事情是,当我打电话“factura.notify”从浏览器,芹菜不能识别任务贝ng被调用,所以它不会发送消息给RabbitMQ。
任何想法,为什么这不工作?
那么什么是你的问题? –
@ ookami.kb公布错误未完成。现在它是它的。谢谢 –
你还没有说过什么不工作。怎么了?你打电话给芹菜的地方在哪里? –