나는 앞으로 나가 알고있는 몇 가지 솔루션은 이 문제에 대한 주위에 떠있는,비록 그들의 아무도는 이 가이드를 따라 여기 고 보이지 않는 내 질문에 대답.
나는 받는 이 오류가 나의 셀러리그에서 플라스크.
[2021-11-23 22:50:01,469: ERROR/ForkPoolWorker-1] Task smartful_versioning_flask.test_celery_task[6dda4a4b-cf64-4fdc-8317-237dca9ad31b] raised unexpected: RuntimeError('Working outside of application context.\n\nThis typically means that you attempted to use functionality that needed\nto interface with the current application object in some way. To solve\nthis, set up an application context with app.app_context(). See the\ndocumentation for more information.')
Traceback (most recent call last):
File "/var/smartful_flask/smartful_venv/lib/python3.7/site-packages/celery/app/trace.py", line 450, in trace_task
R = retval = fun(*args, **kwargs)
File "/var/smartful_flask/smartful_venv/lib/python3.7/site-packages/celery/app/trace.py", line 731, in __protected_call__
return self.run(*args, **kwargs)
File "/var/smartful_flask/smartful_versioning_flask.py", line 21, in test_celery_task
return jsonify({"something": "something"})
File "/var/smartful_flask/smartful_venv/lib/python3.7/site-packages/flask/json/__init__.py", line 336, in jsonify
if current_app.config["JSONIFY_PRETTYPRINT_REGULAR"] or current_app.debug:
File "/var/smartful_flask/smartful_venv/lib/python3.7/site-packages/werkzeug/local.py", line 422, in __get__
obj = instance._get_current_object()
File "/var/smartful_flask/smartful_venv/lib/python3.7/site-packages/werkzeug/local.py", line 544, in _get_current_object
return self.__local() # type: ignore
File "/var/smartful_flask/smartful_venv/lib/python3.7/site-packages/flask/globals.py", line 47, in _find_app
raise RuntimeError(_app_ctx_err_msg)
**RuntimeError: Working outside of application context.**
This typically means that you attempted to use functionality that needed
to interface with the current application object in some way. To solve
this, set up an application context with app.app_context(). See the
documentation for more information.
후 많은 문제해결,나는 완전한 손실이다. 는 곳 중 하나를 통과 앱으로 컨텍스트에서 참조하는 예외?
from flask import Flask, jsonify
from celery import Celery
app = Flask(__name__)
app.config['CELERY_BROKER_URL'] = 'redis://localhost:6379/0'
app.config['CELERY_RESULT_BACKEND'] = 'redis://localhost:6379/0'
celery = Celery(app.name, broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config)
@celery.task
def test_celery_task():
return jsonify({"something": "something"})
@app.route("/web/start/backend", methods=['POST'])
def start_task():
task = test_celery_task.apply_async()
return task.id
@app.route("/web/check-status/backend/<task_id>", methods=['GET'])
def check_task(task_id):
task = test_celery_task.AsyncResult(task_id)
if task.state == 'PENDING':
return jsonify({
"task": task_id,
"state": task.state,
"data": None,
"complete": False,
"error": False
})
elif task.state == 'SUCCESS':
print(task.info)
else:
print(task.state)
return "task.info"
if __name__ == "__main__":
app.run()
으로 예상되는 이 여행에서 빠 작업이 실패 반환하지 않에서 수 있습니다. 내가 사용하 Ngnix,wsgi,관리자를 제공이지만 동일한 문제가 있으로 또는 감독자 산란은 노동자입니다.
나는 확신이 어리석은 사소한 것 나는 있지만,평소에 따-도 장님이 그것을 참조하십시오.