我指定了代理URL。
def create_app():
app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///persistent/msr.db"
app.config["SECRET_KEY"] = "lelsosecret"
app.config["CELERY_BROKER_URL"] = "amqp://guest:guest@msr:5672"
app.config["CELERY_RESULT_BACKEND"] = "db+sqlite:///persistent/msr.db"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db.init_app(app)
celery.init_app(app)
return app
在extensions.py中,有一些相关代码。
class FlaskCelery(Celery):
def __init__(self, *args, **kwargs):
super(FlaskCelery, self).__init__(*args, **kwargs)
self.patch_task()
if "app" in kwargs: self.init_app(kwargs["app"])
def patch_task(self):
TaskBase = self.Task
_celery = self
class ContextTask(TaskBase):
abstract = True
def __call__(self, *args, **kwargs):
if flask.has_app_context():
return TaskBase.__call__(self, *args, **kwargs)
else:
with _celery.app.app_context():
return TaskBase.__call__(self, *args, **kwargs)
self.Task = ContextTask
def init_app(self, app):
self.app = app
self.config_from_object(app.config)
auth = HTTPBasicAuth()
celery = FlaskCelery()
db = SQLAlchemy()
但是,无论我将其更改为什么,Celery都不会真正设置代理URL。
Cannot connect to amqp://guest:**@127.0.0.1:5672//: [Errno 111] Connection refused.
Docker Compose正在运行它,这是真的。但是在docker(我以前的“根深蒂固”的结构)外部执行此操作,也从未允许我更改代理URL。
为什么会这样?
答案 0 :(得分:0)
设置app.config["BROKER_URL"]
而非app.config["CELERY_BROKER_URL"]
会为我切换代理URL。我不确定为什么这是必要的,或者为什么它实际上根本无法工作。