Commit 7c292738 authored by Landon DeCoito's avatar Landon DeCoito
Browse files

implemented threading to run schedules, finalising the cacheing system

parent 595909f2
...@@ -4,25 +4,20 @@ from flask import Response ...@@ -4,25 +4,20 @@ from flask import Response
from flask import render_template from flask import render_template
# app imports # app imports
from appmethods import updatebothdbs from appmethods import updatebothdbs, runscheduleloop
from redisactions import redisdb from redisactions import redisdb
# python imports # python imports
import json import json
# import time import thread
# other imports # other imports
import redis import redis
import schedule
# setting up flask instance # setting up flask instance
app = Flask(__name__) app = Flask(__name__)
# setting up cacheing
schedule.every().day.at("02:00").do(updatebothdbs)
# schedule.every(5).seconds.do(updatebothdbs)
@app.route("/") @app.route("/")
def display_default(): def display_default():
...@@ -44,19 +39,16 @@ def display_GC_data(): ...@@ -44,19 +39,16 @@ def display_GC_data():
return resp return resp
@app.route("/updatedbs") @app.route("/api/lastupdate")
def updateroute(): def getlastupdate():
return Response(updatebothdbs().replace("\n","</br>")) resp = Response(redisdb.lindex("dbupdatelog", 0).replace("\n", "</br>"))
return resp
def shutdown():
runScheduler = False
request.environ.get('werkzeug.server.shutdown')
# this needs to be uncommented in order for the scheduler to work try:
# but it's being weird cause it's hogging the thread thread.start_new_thread(runscheduleloop, ())
# runScheduler = True print "started thread!"
# while runScheduler: except:
# schedule.run_pending() print "===================================================" \
# time.sleep(5) + "Unable to start scheduling thread" \
+ "==================================================="
...@@ -6,9 +6,11 @@ import redisactions as f ...@@ -6,9 +6,11 @@ import redisactions as f
# python imports # python imports
import json import json
import datetime import datetime
import time
# other imports # other imports
import redis import redis
import schedule
# attempts to update both dbs and logs the result # attempts to update both dbs and logs the result
...@@ -21,9 +23,19 @@ def updatebothdbs(): ...@@ -21,9 +23,19 @@ def updatebothdbs():
+ "\nGC: " + str(gcsuccess) + "\nGC: " + str(gcsuccess)
f.appendtoupdatelog(successLog) f.appendtoupdatelog(successLog)
return successLog return successLog
def testprint(): def testprint():
print "Schedule action completed!" 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)
...@@ -18,6 +18,7 @@ import redis ...@@ -18,6 +18,7 @@ import redis
# setting up redis database # setting up redis database
redisdb = redis.from_url("redis://localhost:6379/0", db=0) redisdb = redis.from_url("redis://localhost:6379/0", db=0)
# this will update the live dictlist and the cachedate # this will update the live dictlist and the cachedate
# returns true if the dictlist is not empty, false otherwise # returns true if the dictlist is not empty, false otherwise
def gcdbfill(dictlist): def gcdbfill(dictlist):
...@@ -47,4 +48,4 @@ def livedbfill(dictlist): ...@@ -47,4 +48,4 @@ def livedbfill(dictlist):
def appendtoupdatelog(logstring): def appendtoupdatelog(logstring):
redisdb.lpush("dbupdatelog", logstring) redisdb.lpush("dbupdatelog", logstring)
return redisdb.lrange("dbupdatelog", 0, 0) == logstring return redisdb.lindex("dbupdatelog", 0) == logstring
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment