gpt4 book ai didi

django - 无法在 debug = False(生产)中使用 Django 启动工作进程 Celery 任务

转载 作者:可可西里 更新时间:2023-11-01 11:23:35 26 4
gpt4 key购买 nike

这是一个用于发送电子邮件的 Celery 任务,有趣的是在 DEBUG = True 模式下一切正常,但在生产 DEBUG = False 模式下却不起作用。在发送操作期间并在激活的 Debug模式下运行 celery worker -A invoice2 --loglevel = debug 显示以下内容:

 ERROR/ForkPoolWorker-5] Task enviar_documentos[xxx] raised unexpected: TypeError("enviar_documentos_async() got an unexpected keyword argument 'cliente'",)

首先是延迟发送的文件:

from django.conf import settings
from notifications.tasks import send_async_documents

def send_documents (company, client, documents, type, template = "invoice", context = None):
send_documents = send_documents_async.delay
send_documents (type = type,
                    company = company.pk,
                    client = client.pk,
                    template = template,
                    context = context)

二、任务:

from celery_app import app
@app.task (name = "send_documents")

def enviar_documentos_async (company, client, documents, type = "FacturaVenta", template = "invoice", context = None):
if not context:
context = {}
klass = KLASS.get (type)
queryset = klass.objects.filter (pk__in = documents)
em = Empresa.objects.get (pk = company)
cl = Cliente.objects.get (pk = client)
.
.
return send_email(
mail_from = "\"{0.name}\"><{0.email}>".format(em),
mail_to = cl.email,
type = template,
context = context,
attachments = attachments)

三、邮件的发送:

from django.core.mail import EmailMessage
from django.template import Context, Template

def send_email(mail_from, mail_to, type, context = None, attachments = None):
subject = Template(subject.type).render(mail_context) .replace ("\ n", "")
message = Template(type.body).render(mail_context)
   ...
   msg = EmailMessage (
          subject,
          linebreaks (message),
          mail_from,
          mail_to)

在 virtualenv 中通过 pip 安装的版本应用程序:

   celery 4.3.0

Django 2.1.1

django-extensions 2.0.7

django-filter 2.1.0

django-oauth-toolkit 1.1.3

django-redis 4.10.0

django-redis-cache 2.0.0

djangorestframework 3.8.2

redis 3.2.1

redis-cache 0.1.5

redis-structures 0.1.7

kombu 4.5.0

在服务器 Linux-4.9.0-3-amd64-x86_64-with-debian-9.0 + nginx/1.10.2 + uwsgi 2.0.17.1 上:

Redis server v = 5.0.4 sha = 00000000: 0 malloc = jemalloc-5.1.0 bits = 64
Celery 4.3.0 (rhubarb)

Settings.py 的一部分

DJANGO_ROOT = dirname (abspath (__ file__))
SITE_HTDOCS = normpath (join (DJANGO_ROOT, '../htdocs'))
STATIC_ROOT = normpath (join (SITE_HTDOCS, 'static'))
STATIC_URL = '/static/'
MEDIA_ROOT = normpath (join (SITE_HTDOCS, 'media'))
MEDIA_URL = '/media/'
...
# CELERY
BROKER_URL = 'redis://localhost:6379/0'
CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'

最佳答案

你在哪里调用enviar_documentos_async函数?可能是您提供 client 参数(cliente 而不是 client)的拼写错误。

关于django - 无法在 debug = False(生产)中使用 Django 启动工作进程 Celery 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55900756/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com