I have a Flask web hosting with no access to cron
command.
How can I execute some Python function every hour?
You might want to use some queue mechanism with scheduler like RQ scheduler or something more heavy like Celery (most probably an overkill).
I've tried using flask instead of a simple apscheduler what you need to install is
pip3 instal flask_apscheduler
Below is the sample of my code:
from flask import Flask
from flask_apscheduler import APScheduler
app = Flask(__name__)
scheduler = APScheduler()
def scheduleTask():
print("This test runs every 3 seconds")
if __name__ == '__main__':
scheduler.add_job(id = 'Scheduled Task', func=scheduleTask, trigger="interval", seconds=3)
scheduler.start()
app.run(host="0.0.0.0")
Another alternative might be to use Flask-APScheduler which plays nicely with Flask, e.g.:
More information here:
https://pypi.python.org/pypi/Flask-APScheduler