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

implemented threading to run schedules, finalising the cacheing system

parent 595909f2
......@@ -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 time
import thread
# 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" \
+ "==================================================="
......@@ -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():
+ "\nGC: " + 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)
......@@ -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.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