Created
April 29, 2016 07:33
-
-
Save sivabudh/024808949b496f63d6d9306e840b71ca to your computer and use it in GitHub Desktop.
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
from datetime import datetime, timedelta | |
import sys | |
import os | |
from flask import Flask | |
from apscheduler.schedulers.background import BackgroundScheduler | |
app = Flask(__name__) | |
scheduler = BackgroundScheduler() | |
def alarm(): | |
print('Alarm! This alarm was scheduled') | |
def hello_el(): | |
print("Hey, El! Get shit done!") | |
@app.route('/') | |
def hello_world(): | |
scheduler.add_job(hello_el, 'interval', seconds=2) | |
return 'Hello World!' | |
if __name__ == '__main__': | |
url = 'sqlite:///hello.sqlite3' | |
scheduler.add_jobstore('sqlalchemy', url=url) | |
alarm_time = datetime.now() + timedelta(seconds=10) | |
scheduler.add_job(alarm, 'interval', seconds=3) | |
print('To clear the alarms, delete the example.sqlite file.') | |
print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C')) | |
try: | |
scheduler.start() | |
app.run(host='localhost') | |
except (KeyboardInterrupt, SystemExit): | |
print("You want to stop the progrm.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment