Skip to content
Snippets Groups Projects
Commit b1fcaefe authored by Julian Rother's avatar Julian Rother
Browse files

Replace time stub with a decorator-based scheduler

parent e775cf0e
Branches
No related tags found
No related merge requests found
......@@ -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():
scheduler = sched.scheduler()
def run_scheduler():
while True:
scheduler.run()
def sched_func(delay, priority=0, args=[], kargs={}):
def wrapper(func):
def sched_wrapper():
with app.test_request_context():
pass # do something
timer = threading.Timer(60*60, timer_func)
timer.start()
func(*args, *kargs)
scheduler.enter(delay, priority, sched_wrapper)
scheduler.enter(delay, priority, sched_wrapper)
return func
return wrapper
timer = threading.Timer(0, timer_func)
timer.daemon = True
timer.start()
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'])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment