【问题标题】:Celery configuration for Flask applicationFlask 应用程序的 Celery 配置
【发布时间】:2017-01-01 12:31:24
【问题描述】:

我已将 Celery 配置为在开发盒上为 Flask 应用程序运行异步作业,如下所示:

config.py:

class CeleryConfig(object):
   CELERY_BROKER_URL = 'redis://localhost:6379/0'
   CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'
CELERY_CONFIG = CeleryConfig

ma​​nage.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

以及以下反复出现的错误:

错误/MainProcess 消费者:无法连接到 amqp://guest:**@127.0.0.1:5672//:[Errno 111] 连接被拒绝。

我不确定传输层为什么使用 RabbitMQ 以及为什么我无法启动 Celery。

【问题讨论】:

    标签: python flask redis rabbitmq celery


    【解决方案1】:

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

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

    【讨论】:

    猜你喜欢
    • 2017-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-15
    • 2019-10-04
    • 1970-01-01
    • 2016-02-29
    相关资源
    最近更新 更多