Skip to content

Instantly share code, notes, and snippets.

@sivabudh
Created April 29, 2016 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sivabudh/024808949b496f63d6d9306e840b71ca to your computer and use it in GitHub Desktop.
Save sivabudh/024808949b496f63d6d9306e840b71ca to your computer and use it in GitHub Desktop.
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