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
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ import os ...@@ -7,6 +7,7 @@ import os
import sys import sys
import hashlib import hashlib
import random import random
import sched
app = Flask(__name__) app = Flask(__name__)
...@@ -16,15 +17,22 @@ app.add_template_global(random.randint, name='randint') ...@@ -16,15 +17,22 @@ app.add_template_global(random.randint, name='randint')
app.add_template_global(datetime, name='datetime') app.add_template_global(datetime, name='datetime')
app.add_template_global(timedelta, name='timedelta') 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(): with app.test_request_context():
pass # do something func(*args, *kargs)
timer = threading.Timer(60*60, timer_func) scheduler.enter(delay, priority, sched_wrapper)
timer.start() scheduler.enter(delay, priority, sched_wrapper)
return func
return wrapper
timer = threading.Timer(0, timer_func) threading.Thread(target=run_scheduler, daemon=True).start()
timer.daemon = True
timer.start()
config = app.config config = app.config
config.from_pyfile('config.py.example', silent=True) config.from_pyfile('config.py.example', silent=True)
...@@ -272,7 +280,7 @@ tabs = { ...@@ -272,7 +280,7 @@ tabs = {
'featured': ('featured', 'id', ['title', 'text', 'internal', 'visible', 'deleted'], 'featured': ('featured', 'id', ['title', 'text', 'internal', 'visible', 'deleted'],
['created_by', 'time_created', 'time_updated']), ['created_by', 'time_created', 'time_updated']),
'auth': ('auth', 'auth_id', ['auth_type', 'auth_user', 'auth_passwd'], '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']) @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