I have a flask app which needs to run some of the methods as background tasks. I have been trying to use apscheduler. Background tasks which do not require app_context run without issue, however, tasks which do require it always throw an error:
RuntimeError: Working outside of application context.
I have tried various options. 1. I have passed app into the job, and altered all the jobs to accept app as a parameter.
I have tried to force the background task to start an app with the following:
class APScheduler(_BaseAPScheduler):
def start(self):
app = create_app()
apply_config(app)
with app.app_context():
super().start()
Both options do not appear to have managed to get app_context. Are there any other ways to force the background task to have app_context?