Django芹菜电子邮件,芹菜不工作

时间:2014-09-10 14:04:25

标签: python django django-celery celery-task

我正在研究django celery发送regsitration电子邮件,但芹菜的工作不正确。

我的错误是芹菜

[2014-09-10 19:11:44,349: WARNING/MainProcess] celery@Jeet-PC ready.
[2014-09-10 19:13:38,586: INFO/MainProcess] Received task:       apps.kashmiri.tasks.SignUpTask[17ca2ae1-8c72-426c-babd-470a55ac19
5]
[2014-09-10 19:13:38,936: ERROR/Worker-1] Pool process <Worker(Worker-1, started)> error:     RuntimeError(RuntimeError("App reg
stry isn't ready yet.",), <function model_unpickle at 0x034E4B30>, (('auth', 'User'), [],     <function simple_class_factory at
x034E4AF0>))
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\billiard\pool.py", line 289, in run
sys.exit(self.workloop(pid=pid))
File "C:\Python27\lib\site-packages\billiard\pool.py", line 350, in workloop
req = wait_for_job()
File "C:\Python27\lib\site-packages\billiard\pool.py", line 441, in receive
ready, req = _receive(1.0)
File "C:\Python27\lib\site-packages\billiard\pool.py", line 413, in _recv
return True, loads(get_payload())
File "C:\Python27\lib\site-packages\billiard\common.py", line 77, in pickle_loads
return load(BytesIO(s))
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 1450, in model_unpickle
model = apps.get_model(*model_id)
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 187, in get_model
self.check_ready()
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 119, in check_ready
raise RuntimeError("App registry isn't ready yet.")
RuntimeError: (RuntimeError("App registry isn't ready yet.",), <function model_unpickle at    0x034E4B30>, (('auth', 'User'), [
, <function simple_class_factory at 0x034E4AF0>))
[2014-09-10 19:13:39,233: ERROR/MainProcess] Process 'Worker-3' pid:7100 exited with 'signal -1'

forms.py

from apps.kashmiri.tasks import SignUpTask
SignUpTask.delay(user=user)

celery.py

from __future__ import absolute_import

import os

from celery import Celery
from django.conf import settings


os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'kb.settings')

app=Celery('kb')

app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

@app.task(bind= True)
def debug_task(self):
print('Request:{0!r}'.format(self.request))

tasks.py

from __future__ import absolute_import
from celery.registry import tasks
from celery.task import Task
from celery.app import shared_task
from django.utils.html import strip_tags
from django.core.mail import EmailMultiAlternatives
from django.template.loader import render_to_string

class SignUpTask(Task):
def run(self, user):
    subject, from_email, to ='Welcome to Kashmiri Bhatta', 'info@seekersguru.com', user.email
    html_content = render_to_string('registration.html',{'user':user.email})
    text_content= strip_tags(html_content)
    msg= EmailMultiAlternatives(subject, text_content, from_email, [to])
    msg.attach_alternative(html_content, "text/html")
    msg.send()

tasks.register(SignUpTask)

当我使用&gt;&gt; celery -A proj worker -l info

运行时错误的

错误:(运行时错误(“应用程序注册表尚未就绪。”) 请帮忙解决..

1 个答案:

答案 0 :(得分:1)

Django 1.7出现此问题。它是在github上报告的并且是固定的recenlty。升级到最新版本的Celery。它应该解决问题

pip install celery --upgrade