我已经将celery配置为在开发框上为Flask应用程序运行异步作业,如下所示:
config.py:
class CeleryConfig(object):
CELERY_BROKER_URL = 'redis://localhost:6379/0'
CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'
CELERY_CONFIG = CeleryConfig
manage.py:
celery_app = celery.Celery(config_source=app.config.get('CELERY_CONFIG'))
def run_celery():
appl = celery.current_app._get_current_object()
celery_worker = celery_worker.worker(app=appl)
options = {
'broker': config.get('CELERY_CONFIG').CELERY_BROKER_URL,
'traceback': True,
}
celery_worker.run(**options)
在启动应用程序之前,我开始redis:
./redis-server --daemonize yes
然后当我运行应用程序(run_celery)时,我显示以下celery配置:
以及以下反复出现的错误:
ERROR / MainProcess使用者:无法连接到amqp:// guest:** @ 127.0.0.1:5672 //:[Errno 111]连接被拒绝。
我不确定为什么传输层使用RabbitMQ以及为什么我不能开始使用芹菜。
答案 0 :(得分:1)
这是因为参数是BROKER_URL
,而不是CELERY_BROKER_URL
。以下是可能设置的完整列表:http://docs.celeryproject.org/en/latest/userguide/configuration.html#new-lowercase-settings
注意:该表是Celery 4.0中新小写设置的转换表,但如上所述:“Celery仍然可以读取旧的配置文件,因此不必急于转换到新的设置格式”