简体   繁体   English

如何将 celery 设置添加到 django?

[英]How to add celery settings to django?

I would like to add the following celery setting modification to the django app我想在 django 应用程序中添加以下 celery 设置修改

worker_send_task_event = False
task_ignore_result = True
task_acks_late = True 
worker_prefetch_multiplier = 10  

In my celery.py, I got在我的 celery.py 中,我得到了

import os

from celery import Celery

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

app = Celery('server')

app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()

And my tasks.py还有我的tasks.py

@shared_task
def some_task():
    pass

Celery is executed using the following Celery 使用以下命令执行

command: celery -A server worker -Ofair — without-gossip — without-mingle — without-heartbeat

I have added them directly to the Django settings.py but I am not sure if Celery actually picked those settings up.我已将它们直接添加到 Django settings.py但我不确定 Celery 是否真的选择了这些设置。 So I am wondering if there is another way to add them or someone has a similar experience?所以我想知道是否有其他方法可以添加它们或有人有类似的经历?

I am using我在用

celery==5.2.1
Django==3.2.5

You need to use upper case naming like described here您需要使用此处描述的大写命名

Example: Use CELERYD_SEND_EVENTS = True istead of worker_send_task_event = False示例:使用CELERYD_SEND_EVENTS = True而不是worker_send_task_event = False

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

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