pythonpython-3.xflaskredispython-rq

RQ Python "Working outside of application context"


I'm trying to use Redis & RQ to set the task of sending an email, however, the "RQ Worker" is returning runtime error while using the function to send emails outside q.enqueue works fine.

Which is outside the app folder

    from app import create_app

    app = create_app()

    if __name__ == '__main__':
        app.run(debug=True)

Solution

  • You're probably missing an app.app_context().push(). The Flask Mega Tutorial does it like this, but I've done it inside the task.