首页 > 解决方案 > Celery 和 Flask - 不能将新设置名称与旧设置名称混合使用

问题描述

我已经使用本教程在我的 Flask 应用程序上设置 Celery,但我不断收到以下错误:

File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\celery\app\base.py", line 141, in data
    return self.callback()
celery.exceptions.ImproperlyConfigured:

Cannot mix new setting names with old setting names, please
rename the following settings to use the old format:

include                              -> CELERY_INCLUDE

Or change all of the settings to use the new format :)

我究竟做错了什么?我使用的代码与教程基本相同:

初始化.py

app = Flask(__name__)
app.config.from_object(Config)
app.config['TESTING'] = True
db = SQLAlchemy(app)
migrate = Migrate(app, db)

def make_celery(app):
    celery = Celery(
        app.import_name,
        backend=app.config['CELERY_RESULT_BACKEND'],
        broker=app.config['CELERY_BROKER_URL']
    )
    celery.conf.update(app.config)

    class ContextTask(celery.Task):
        def __call__(self, *args, **kwargs):
            with app.app_context():
                return self.run(*args, **kwargs)

    celery.Task = ContextTask
    return celery


app.config.update(
    CELERY_BROKER_URL='redis://localhost:6379',
    CELERY_RESULT_BACKEND='redis://localhost:6379'
)
celery = make_celery(app)

标签: pythonpython-3.xflaskcelery

解决方案


您正在使用的代码使用旧变量名将
行更改
app.config.update(
CELERY_BROKER_URL='redis://localhost:6379',
CELERY_RESULT_BACKEND='redis://localhost:6379'
)

app.config.update(
broker_url='redis://localhost:6379',
result_backend='redis://localhost:6379'
)


推荐阅读