Hi! I've been building 2 web apps and I suddenly require scheduling tasks from a SQLDatabase. Adding, editing and deleting has been no issue, but now after installing Advanced Python Scheduler and it's Flask extension, I'm at odds in how to make it run.
1) Installed using pip install --user Flask-APScheduler
2) Created a jobs file using the examples as basis:
class Config(object):
JOBS = [
{
'id': 'job1',
'func': 'jobs:job1',
'args': (1, 2),
'trigger': 'interval',
'seconds': 10
}
]
SCHEDULER_API_ENABLED = True
def job1(a, b):
print(str(a) + ' ' + str(b))
if __name__ == '__main__':
app = Flask(__name__)
app.config.from_object(Config())
scheduler = APScheduler()
# it is also possible to enable the API directly
# scheduler.api_enabled = True
scheduler.init_app(app)
scheduler.start()
app.run()
But I'm stuck in how to implement the last part of scheduler.init_app(app) and app.run() given that PythonAnywhere's configuration of Flask Server is different.
I tried adding this code into WSGI file and got the The scheduler seems to be running under uWSGI, but threads have been disabled. You must run uWSGI with the --enable-threads option for the scheduler to work..
From what I read in other threads, PythonAnywhere doesn't allow threading or Celery. So I wanted to ask if there's any way I can get this running. Given that my applications forcibly need to allow scheduling and triggering alerts when a given date/time occurs, this is a dealbreaker for me.
Also read that I can make use of the Task tab in the Dashboard to schedule them. But does it allow to programatically schedule the events? I can't manually do it because the point of the apps are to check periodically for the scheduled date and times close to be due and then perform actions (sending emails., triggering alerts on the frontend, etc.).
Or is there an easier way to check events scheduled in SQLAlchemy and trigger actions when the date of the events occur?
Thanks in advance for the help!