Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
mason-today-web
Commits
7c292738
Commit
7c292738
authored
Jul 16, 2018
by
Landon DeCoito
Browse files
implemented threading to run schedules, finalising the cacheing system
parent
595909f2
Changes
3
Hide whitespace changes
Inline
Side-by-side
mason-today/__init__.py
View file @
7c292738
...
...
@@ -4,25 +4,20 @@ from flask import Response
from
flask
import
render_template
# app imports
from
appmethods
import
updatebothdbs
from
appmethods
import
updatebothdbs
,
runscheduleloop
from
redisactions
import
redisdb
# python imports
import
json
#
import t
ime
import
t
hread
# other imports
import
redis
import
schedule
# setting up flask instance
app
=
Flask
(
__name__
)
# setting up cacheing
schedule
.
every
().
day
.
at
(
"02:00"
).
do
(
updatebothdbs
)
# schedule.every(5).seconds.do(updatebothdbs)
@
app
.
route
(
"/"
)
def
display_default
():
...
...
@@ -44,19 +39,16 @@ def display_GC_data():
return
resp
@
app
.
route
(
"/updatedbs"
)
def
updateroute
():
return
Response
(
updatebothdbs
().
replace
(
"
\n
"
,
"</br>"
))
def
shutdown
():
runScheduler
=
False
request
.
environ
.
get
(
'werkzeug.server.shutdown'
)
@
app
.
route
(
"/api/lastupdate"
)
def
getlastupdate
():
resp
=
Response
(
redisdb
.
lindex
(
"dbupdatelog"
,
0
).
replace
(
"
\n
"
,
"</br>"
))
return
resp
# this needs to be uncommented in order for the scheduler to work
# but it's being weird cause it's hogging the thread
# runScheduler = True
# while runScheduler:
# schedule.run_pending()
# time.sleep(5)
try
:
thread
.
start_new_thread
(
runscheduleloop
,
())
print
"started thread!"
except
:
print
"==================================================="
\
+
"Unable to start scheduling thread"
\
+
"==================================================="
mason-today/appmethods.py
View file @
7c292738
...
...
@@ -6,9 +6,11 @@ import redisactions as f
# python imports
import
json
import
datetime
import
time
# other imports
import
redis
import
schedule
# attempts to update both dbs and logs the result
...
...
@@ -21,9 +23,19 @@ def updatebothdbs():
+
"
\n
GC: "
+
str
(
gcsuccess
)
f
.
appendtoupdatelog
(
successLog
)
return
successLog
def
testprint
():
print
"Schedule action completed!"
# setting up cacheing
schedule
.
every
().
day
.
at
(
"02:00"
).
do
(
updatebothdbs
)
def
runscheduleloop
():
runScheduler
=
True
while
runScheduler
:
schedule
.
run_pending
()
time
.
sleep
(
1800
)
mason-today/redisactions.py
View file @
7c292738
...
...
@@ -18,6 +18,7 @@ import redis
# setting up redis database
redisdb
=
redis
.
from_url
(
"redis://localhost:6379/0"
,
db
=
0
)
# this will update the live dictlist and the cachedate
# returns true if the dictlist is not empty, false otherwise
def
gcdbfill
(
dictlist
):
...
...
@@ -47,4 +48,4 @@ def livedbfill(dictlist):
def
appendtoupdatelog
(
logstring
):
redisdb
.
lpush
(
"dbupdatelog"
,
logstring
)
return
redisdb
.
l
range
(
"dbupdatelog"
,
0
,
0
)
==
logstring
return
redisdb
.
l
index
(
"dbupdatelog"
,
0
)
==
logstring
Write
Preview
Markdown
is supported
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