flask-apscheduler icon indicating copy to clipboard operation
flask-apscheduler copied to clipboard

Add Flask context automatically to APScheduler executors

Open mxdev88 opened this issue 3 years ago • 5 comments

This PR adds the Flask context to added or modified jobs automaticall. Most of the time when using Flask-APScheduler, you need to access something from your Flask app which requires to add the context yourself.

This should solve issues like mentioned here #176

mxdev88 avatar Aug 14 '21 11:08 mxdev88

I guess this code only works when the jobs are kept in memory, if you use a storage like sqlite/sqlalchemy it won't work.

viniciuschiele avatar Aug 14 '21 11:08 viniciuschiele

Another option may be to act on the part that runs the job rather than on the job itself. Any thoughts on this?

mxdev88 avatar Aug 14 '21 13:08 mxdev88

It is APScheduler that runs the jobs and it doesn't allow me to add some sort of "middleware" to initialize a Flask context before calling the actual method. If you find a workaround for that, I will be happy to merge it.

viniciuschiele avatar Aug 16 '21 08:08 viniciuschiele

Hi @viniciuschiele - made another attempt, this time by decorating executors rather than the jobs. Let me know what you think. thanks!

mxdev88 avatar Aug 22 '21 15:08 mxdev88