Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Video AG Infrastruktur
website
Commits
b1fcaefe
Commit
b1fcaefe
authored
Sep 12, 2016
by
Julian Rother
Browse files
Replace time stub with a decorator-based scheduler
parent
e775cf0e
Changes
1
Hide whitespace changes
Inline
Side-by-side
server.py
View file @
b1fcaefe
...
...
@@ -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'
])
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment