Created
November 2, 2022 13:13
-
-
Save andypiper/0cfeb89a4d77b131b6d34ca9a54ad94b to your computer and use it in GitHub Desktop.
Schedule a task in a Flask app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# useful https://stackoverflow.com/questions/21214270/how-to-schedule-a-function-to-run-every-hour-on-flask | |
# docs https://pypi.org/project/Flask-APScheduler/ | |
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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment