我已将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配置:
  • ** ----------。>传输:amqp:// guest:** @ localhost:5672 //
  • ** ----------。>结果:redis:// localhost:6379/0

  • 以及以下重复出现的错误:



    我不确定为什么传输层使用RabbitMQ,为什么不能启动Celery。

    最佳答案

    这是因为参数是BROKER_URL,而不是CELERY_BROKER_URL。以下是所有可能设置的完整列表:http://docs.celeryproject.org/en/latest/userguide/configuration.html#new-lowercase-settings

    注意:该表是Celery 4.0中新的小写字母设置的转换表,但如此处所述:“Celery仍然能够读取旧的配置文件,因此不必急于转移到新的设置格式”

    关于python - Flask应用程序的 celery 配置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41415467/

    10-12 00:38
    查看更多