Created
February 10, 2014 22:31
-
-
Save mox1/8925587 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#this function allows us to do periodic things | |
#not perfect, but eh. | |
#for now this simply updates the statistics | |
#but could easily be used to do more "cron" like things | |
#this gets called for EVERY page, so don't do any heavy lifting | |
next_cron_run = 0 | |
def my_processor(handler): | |
global next_cron_run | |
if (time.time() > next_cron_run): | |
logger.debug("DOING CRON RUN") | |
thr = threading.Thread(target=update_db) | |
thr.start() | |
next_cron_run = time.time() + (60*60) # run again in 1 hour | |
return handler() | |
app.add_processor(my_processor) | |
def update_db(): | |
global t_globals | |
logger.info("Start updating blog data") | |
m.BlogData.update_stats() | |
blog_data(update=True) | |
logger.info("Finish updating blog data") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment