python - 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)
解决方案
您正在使用的代码使用旧变量名将
行更改
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'
)
推荐阅读
- c++ - 令人不安的评价顺序
- php - 将用户名保存在变量/函数中以备后用
- angular - rxjs switchMap 类型不匹配问题
- linux - GStreamer:具有不会构建的依赖项的插件
- php - 简码中的编辑按钮重定向到数据库 Wordpress 中的项目页面
- python - 如何将 matplotlib 3d 绘图更改为侧视图?
- python - date_parser 和 read_csv 的功能不起作用
- wpf - 中文/Bopomofo 未在 wpf 中的绑定文本属性上触发 PropertyChanged
- java - 应用程序在后台时推送通知的自定义布局问题
- json - 如果键包含点(例如 IP 地址),如何访问 SuperObject 对象?