简体   繁体   English

用Celery设置django项目

[英]setting the django project with Celery

I am trying to set up celery with Django on my development server, running on ubuntu. 我正在尝试在ubuntu上运行的开发服务器上使用Django设置celery。 Following are changes i made. 以下是我所做的更改。

init.py init.py

from __future__ import absolute_import, unicode_literals

from .celery import app as celery_app

__all__ = ['celery_app']

celery.py celery.py

from __future__ import absolute_import
import os
from celery import task
from celery import Celery

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


app = Celery('samplecelery')

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

@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 import shared_task

@shared_task
def add(x, y):
    return x + y

@shared_task
def mul(x, y):
    return x * y

when i run the command to check the worker for samplecelery 当我运行命令以检查工人的样品芹菜

celery -A sampleceleryworker -l info 芹菜-样品芹菜工人-l信息

app=Celery(samplecelery) 应用程式=芹菜(samplecelery)

It tells me the app is not installed. 它告诉我该应用程序尚未安装。 Any thoughts on what might have gone wrong in this setup?can anyone please help me..... ModuleNotFoundError: No module named 'Celery' 关于此设置中可能出了什么问题的任何想法?有人可以帮助我..... ModuleNotFoundError:没有名为“ Celery”的模块

to resolve this error 解决此错误

TypeError: config_from_object() got an unexpected keyword argument 'namespace' TypeError:config_from_object()获得了意外的关键字参数“名称空间”

the solution is here .you need to: 解决方案在这里。您需要:

pip install celery==4.2.0

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

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