diff --git a/server.py b/server.py index e295dd444290631d24164a0e7862de091ee41016..88c5683a8e423c3d7b76ac3599cfaf8399c0134c 100644 --- a/server.py +++ b/server.py @@ -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) - timer.start() +scheduler = sched.scheduler() +def run_scheduler(): + while True: + scheduler.run() -timer = threading.Timer(0, timer_func) -timer.daemon = True -timer.start() +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('config.py.example', 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'])