Commit b1fcaefe authored by Julian Rother's avatar Julian Rother
Browse files

Replace time stub with a decorator-based scheduler

parent e775cf0e
......@@ -7,6 +7,7 @@ import os
import sys
import hashlib
import random
import sched
app = Flask(__name__)
......@@ -16,15 +17,22 @@ app.add_template_global(random.randint, name='randint')
app.add_template_global(datetime, name='datetime')
app.add_template_global(timedelta, name='timedelta')
def timer_func():
with app.test_request_context():
pass # do something
timer = threading.Timer(60*60, timer_func)
scheduler = sched.scheduler()
def run_scheduler():
while True:
timer = threading.Timer(0, timer_func)
timer.daemon = True
def sched_func(delay, priority=0, args=[], kargs={}):
def wrapper(func):
def sched_wrapper():
with app.test_request_context():
func(*args, *kargs)
scheduler.enter(delay, priority, sched_wrapper)
scheduler.enter(delay, priority, sched_wrapper)
return func
return wrapper
threading.Thread(target=run_scheduler, daemon=True).start()
config = app.config
config.from_pyfile('', silent=True)
......@@ -272,7 +280,7 @@ tabs = {
'featured': ('featured', 'id', ['title', 'text', 'internal', 'visible', 'deleted'],
['created_by', 'time_created', 'time_updated']),
'auth': ('auth', 'auth_id', ['auth_type', 'auth_user', 'auth_passwd'],
['auth_id', 'course_id', 'lecture_id', 'video_id'])
['course_id', 'lecture_id', 'video_id'])
@app.route('/edit', methods=['GET', 'POST'])
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment