我遵循芹菜4.0.0的"与django"教程的"第一步":http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html
这一切都按预期工作。但是,如果我尝试通过将其添加到settings.py
的末尾来更改从AMQP到Django Orm的传输:
CELERY_BROKER_URL = 'django://'
然后,当我运行工作过程(celery -A proj worker
)时,我会发现一个错误:
Traceback (most recent call last):
File "/home/ac/src/proj/.pyenv/bin/celery", line 11, in <module>
sys.exit(main())
File "/home/ac/src/proj/.pyenv/local/lib/python2.7/site-packages/celery/__main__.py", line 14, in main
_main()
File "/home/ac/src/proj/.pyenv/local/lib/python2.7/site-packages/celery/bin/celery.py", line 326, in main
cmd.execute_from_commandline(argv)
File "/home/ac/src/proj/.pyenv/local/lib/python2.7/site-packages/celery/bin/celery.py", line 488, in execute_from_commandline
super(CeleryCommand, self).execute_from_commandline(argv)))
File "/home/ac/src/proj/.pyenv/local/lib/python2.7/site-packages/celery/bin/base.py", line 278, in execute_from_commandline
return self.handle_argv(self.prog_name, argv[1:])
File "/home/ac/src/proj/.pyenv/local/lib/python2.7/site-packages/celery/bin/celery.py", line 480, in handle_argv
return self.execute(command, argv)
File "/home/ac/src/proj/.pyenv/local/lib/python2.7/site-packages/celery/bin/celery.py", line 412, in execute
).run_from_argv(self.prog_name, argv[1:], command=argv[0])
File "/home/ac/src/proj/.pyenv/local/lib/python2.7/site-packages/celery/bin/worker.py", line 221, in run_from_argv
return self(*args, **options)
File "/home/ac/src/proj/.pyenv/local/lib/python2.7/site-packages/celery/bin/base.py", line 241, in __call__
ret = self.run(*args, **kwargs)
File "/home/ac/src/proj/.pyenv/local/lib/python2.7/site-packages/celery/bin/worker.py", line 255, in run
**kwargs)
File "/home/ac/src/proj/.pyenv/local/lib/python2.7/site-packages/celery/worker/worker.py", line 99, in __init__
self.setup_instance(**self.prepare_args(**kwargs))
File "/home/ac/src/proj/.pyenv/local/lib/python2.7/site-packages/celery/worker/worker.py", line 120, in setup_instance
self._conninfo = self.app.connection_for_read()
File "/home/ac/src/proj/.pyenv/local/lib/python2.7/site-packages/celery/app/base.py", line 732, in connection_for_read
return self._connection(url or self.conf.broker_read_url, **kwargs)
File "/home/ac/src/proj/.pyenv/local/lib/python2.7/site-packages/celery/app/base.py", line 808, in _connection
'broker_connection_timeout', connect_timeout
File "/home/ac/src/proj/.pyenv/local/lib/python2.7/site-packages/kombu/connection.py", line 179, in __init__
if not get_transport_cls(transport).can_parse_url:
File "/home/ac/src/proj/.pyenv/local/lib/python2.7/site-packages/kombu/transport/__init__.py", line 81, in get_transport_cls
_transport_cache[transport] = resolve_transport(transport)
File "/home/ac/src/proj/.pyenv/local/lib/python2.7/site-packages/kombu/transport/__init__.py", line 62, in resolve_transport
raise KeyError('No such transport: {0}'.format(transport))
KeyError: u'No such transport: django'
我在做什么错?
您可以将其用作结果后端,但不再用作经纪人。
在芹菜项目网站上,受支持的经纪人的列表在这里。
在您关注的"教程"页面中,您可以选择使用Django Orm作为后端:
扩展django-celery-corlults-使用django orm/cache作为一个 结果后端
使用Django-celery-results扩展名提供结果后端 django orm或Django Cache框架。
有关该如何做的完整说明,该指令位于页面上的这一点上。
简短答案-Django orm不再是经纪人,它在版本4.0中被删除。
没有称为django
的传输,因此您无法使用django://
。您可能使用的是这样的RabbitMQ
:
CELERY_BROKER_URL = 'amqp://guest:guest@localhost:5672//'
我在使用拆分分配和周围时遇到了这个问题。我留下了"设置文件"中的报价,而环境不喜欢引号。
打印/记录您为连接提供的值(来自settings.py的值)。检查您是否没有其他符号(引号)。