How to keep a request context in a celery task, in Python Flask?

前端 未结 1 1359
不思量自难忘°
不思量自难忘° 2021-01-18 03:10

Is there a way to copy the request to a celery task in Flask in such a manner that the task executes inside the request context which initiated the task?
I need to acces

相关标签:
1条回答
  • 2021-01-18 03:51

    The is no out-of-the-box way to pass the request or current_user objects to the celery task as they are non serializable. But people have worked around this by creating a wrapper to call the celery task in the request context.

    The Celery task in a Flask request context blog post explores this topic in detail. The gists by Xion and derived one by aviaryan with the Request Context wrapper.

    0 讨论(0)
提交回复
热议问题