2017-06-12 127 views
1

我已经将Django从版本1.7升级到版本1.11.2,并将芹菜从版本3.1.25升级到版本4.0.1。如何在Django中运行芹菜工1.11

此升级之前,我是能够运行芹菜工作人员这样扔django-celery包:

python manage.py celery worker -Q <my_queue> --app=proj.celery:app --concurrency=5 

阅读芹菜发行说明和文档,我发现使用Django的ORM,结果后台,我可以我不再使用django-celery包,但我必须使用django-celery-resultsdjango-celery-beat,而不是它。

使用相同的命令我不能再运行工人。
更详细我尝试运行以下命令:

celery worker -app=proj.celery:app -l info 

其中芹菜是我的virtualenv的celery.exe文件(virtual_env_name \脚本\ celery.exe)。

这提出了以下错误:

Traceback (most recent call last): 
    File "c:\python27\Lib\runpy.py", line 162, in _run_module_as_main 
"__main__", fname, loader, pkg_name) 
File "c:\python27\Lib\runpy.py", line 72, in _run_code 
    exec code in run_globals 
    File "C:\Python27\virtualenv\<virtual_env_name>\Scripts\celery.exe\__main__.py", line 5, in <module> 
    File "path\of\my\project\celery.py", line 8, in <module> 
    from celery import Celery 
ImportError: cannot import name Celery 

我试图直接在命令行中输入芹菜,并且效果很好。当我运行该命令的问题被提升

celery.py文件

from __future__ import absolute_import 
import os 
from celery import Celery 
import django 

django.setup() 

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

app = Celery('proj') 

app.config_from_object('django.conf:settings') 
app.autodiscover_tasks() 


@app.task(bind=True) 
def debug_task(self): 
    print('Request: {0!r}'.format(self.request)) 

项目结构

- main 
    - proj 
     - __init__.py 
     - setting.py 
     - celery.py 
- manage.py 

我运行Python2.7和Windows 32

在此先感谢

回答

0

Celery 4 documentation

Microsoft Windows is no longer supported.

The test suite is passing, and Celery seems to be working with Windows, but we make no guarantees as we are unable to diagnose issues on this platform. If you are a company requiring support on this platform, please get in touch.

不幸的是,它不再能够在Windows上运行芹菜工人。你必须留在3.1.x版本...

+0

是的,我已经读过它,但似乎它不支持,但测试套件通过.. – Giordano

+0

其实,我没有问题在Windows上导入Celery 4,但我有台球和ampq问题(请参阅:https://github.com/celery/celery/issues/4082)无论如何,现在,在Windows上使用芹菜4是非常困难的,只要它不是固定的/修补/分叉,你应该坚持芹菜3 – Antwane

+0

感谢您的链接!无论如何,如果我尝试从命令行( virtualenv的python)导入芹菜效果很好。当我运行芹菜命令时引发的问题... – Giordano