Last active
April 1, 2024 04:06
-
-
Save ivanleoncz/21293b00d0ea54db8ee3b57fb1170ddf to your computer and use it in GitHub Desktop.
Demonstrating APScheduler on a Flask App.
This file contains 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
#!/usr/bin/python3 | |
""" Demonstrating APScheduler feature for small Flask App. """ | |
from apscheduler.schedulers.background import BackgroundScheduler | |
from flask import Flask | |
def sensor(): | |
""" Function for test purposes. """ | |
print("Scheduler is alive!") | |
sched = BackgroundScheduler(daemon=True) | |
sched.add_job(sensor,'interval',seconds=60) | |
sched.start() | |
app = Flask(__name__) | |
@app.route("/home") | |
def home(): | |
""" Function for test purposes. """ | |
return "Welcome Home :) !" | |
if __name__ == "__main__": | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It seems so. I forked the code above on my machine and then added a statement for printing the timestamp of each execution of
sensor()
:Worth reading the API documentation tough, besides making your own tests in order to validate if the library suits your needs or not:
Regards,