【问题标题】:Django Celery email, celery is not workingDjango Celery 电子邮件,芹菜不工作
【发布时间】:2014-09-10 14:04:24
【问题描述】:

我正在使用 django celery 发送注册电子邮件,但 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

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

芹菜.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)

当我使用 >> celery -A proj worker -l info

RuntimeError 的错误:(RuntimeError("App registry is not ready.",) 请帮助解决它..

【问题讨论】:

  • 你在使用django 1.7吗?
  • 我正在使用当前版本

标签: python django django-celery celery-task


【解决方案1】:

这个问题只发生在Django 1.7。在 github 上报告并修复了recenlty。升级到最新版本的 Celery。应该能解决问题

pip install celery --upgrade 

【讨论】:

    猜你喜欢
    • 2015-12-16
    • 2018-05-08
    • 2015-06-01
    • 1970-01-01
    • 2014-09-07
    • 2011-05-31
    • 2021-07-12
    • 2019-06-04
    • 1970-01-01
    相关资源
    最近更新 更多