我有一个以下项目目录:
azima:
__init.py
main.py
tasks.py
task.py
from .main import app
@app.task
def add(x, y):
return x + y
@app.task
def mul(x, y):
return x * y
@app.task
def xsum(numbers):
return sum(numbers)
main.py
from celery import Celery
app = Celery('azima', backend='redis://localhost:6379/0', broker='redis://localhost:6379/0', include=['azima.tasks'])
# Optional configuration, see the application user guide.
app.conf.update(
result_expires=3600,
)
if __name__ == '__main__':
app.start()
当我运行命令来初始化 celery 工作人员时,出现以下错误:
(azima_venv) brightseid@darkseid:~$ celery -A azima worker -l INFO
Usage: celery [OPTIONS] COMMAND [ARGS]...
Error: Invalid value for '-A' / '--app':
Unable to load celery application.
Module 'azima' has no attribute 'celery'
但当我重命名时main.py
to celery.py
和之前一样,没有任何问题。
我在这里缺少什么?
有两种方法
- 导入你的
app
to azima/__init__.py
from azima.main import app
celery = app # you can omit this line
您可以省略最后一行,celery 将从导入中识别 celery 应用程序。然后你打电话celery -A azima worker -l INFO
- 打电话给你的应用程序就像
celery -A azima.main worker -l INFO
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)