简体   繁体   English

Django Celery电子邮件,芹菜不起作用

[英]Django Celery email, celery is not working

i am working on django celery for sending the regsitration email ,but the celery is not working correct. 我正在处理django celery,用于发送注册电子邮件,但是celery不能正常工作。

my error is in celery 我的错误是芹菜

[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 forms.py

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

celery.py 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 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)

When im using >> celery -A proj worker -l info 当我使用>> 芹菜时-项目工作者-l信息

error for RuntimeError: (RuntimeError("App registry isn't ready yet.",) please help for solving it.. RuntimeError错误:( RuntimeError(“ App注册表尚未准备好。”,)请帮助解决它。

This problem occurs only with Django 1.7 . 仅在Django 1.7会出现此问题。 It was reported on github and was fixed recenlty . 据报道,在github上,并固定recenlty Upgrade to latest version of Celery. 升级到最新版本的Celery。 It should solve the problem 它应该解决问题

pip install celery --upgrade 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM