def persist_task(): """Persist all gae/bingo cache entities to the datastore. After persisting, this task should queue itself up for another run quickly thereafter. This function uses a lock to make sure that only one persist task is running at a time. """ lock = PersistLock() # Take the lock (only one persist should be running at a time) if not lock.take(): logging.info("Skipping gae/bingo persist, persist lock already owned.") return logging.info("Persisting gae/bingo state from memcache to datastore") try: # Make sure request and instance caches are flushed, because this task # doesn't go through the normal gae/bingo WSGI app which is wrapped in # middleware. Regardless, we want to flush instance cache so that we're # persisting the current shared memcache state of all exercises to the # datastore. request_cache.flush_request_cache() instance_cache.flush() cache.BingoCache.get().persist_to_datastore() cache.BingoIdentityCache.persist_buckets_to_datastore() finally: # Always release the persist lock lock.release() # In production, at the end of every persist task, queue up the next one. # An unbroken chain of persists should always be running. if not os.environ["SERVER_SOFTWARE"].startswith('Development'): queue_new_persist_task()
def persist_task(): """Persist all gae/bingo cache entities to the datastore. After persisting, this task should queue itself up for another run quickly thereafter. This function uses a lock to make sure that only one persist task is running at a time. """ lock = PersistLock() # Take the lock (only one persist should be running at a time) if not lock.take(): logging.info("Skipping gae/bingo persist, persist lock already owned.") return logging.info("Persisting gae/bingo state from memcache to datastore") try: # Make sure request and instance caches are flushed, because this task # doesn't go through the normal gae/bingo WSGI app which is wrapped in # middleware. Regardless, we want to flush instance cache so that we're # persisting the current shared memcache state of all exercises to the # datastore. request_cache.flush_request_cache() instance_cache.flush() cache.BingoCache.get().persist_to_datastore() cache.BingoIdentityCache.persist_buckets_to_datastore() finally: # Always release the persist lock lock.release() # In production, at the end of every persist task, queue up the next one. # An unbroken chain of persists should always be running. if not os.environ["SERVER_SOFTWARE"].startswith("Development"): queue_new_persist_task()
def flush_in_app_caches(self): """Flush in-app request and instance caches of gae/bingo state.""" request_cache.flush_request_cache() instance_cache.flush()