def run_ctx_request(environ):
"""
run flask request context in celery worker
"""
from blueprints import app # wsgi.app
if '_wsgi.input' in environ:
# an input stream (file-like object) from which the HTTP request body can be read.
# detail: https://www.python.org/dev/peps/pep-0333/#environ-variables
environ['wsgi.input'] = BytesIO(environ['_wsgi.input'])
with app.request_context():
g.in_celery = True
try:
rv = app.full_dispatch_request()
except InternalServerError:
if app.debug:
raise
return app.make_response(InternalServerError())
return (rv.get_data(), rv.status_code, rv.headers)
评论列表
文章目录