示例#1
0
    def __call__(self, environ, start_response):

        try:
            # Make sure request-cached values are cleared at start of request
            request_cache.flush_request_cache()

            def gae_bingo_start_response(status, headers, exc_info = None):

                if identity.using_logged_in_bingo_identity():
                    if identity.get_identity_cookie_value():
                        # If using logged in identity, clear cookie b/c we don't need it
                        # and it can cause issues after logging out.
                        headers.append(("Set-Cookie",
                                        identity.delete_identity_cookie_header()))
                else:
                    # Not using logged-in identity. If current identity isn't
                    # already stored in cookie, do it now.
                    if identity.identity() != identity.get_identity_cookie_value():
                        headers.append(("Set-Cookie",
                                        identity.set_identity_cookie_header()))

                return start_response(status, headers, exc_info)

            result = self.app(environ, gae_bingo_start_response)
            for value in result:
                yield value

            # Persist any changed GAEBingo data to memcache
            cache.store_if_dirty()

            # If we got a new ID, we should put it to the datastore so it persists
            identity.put_id_if_necessary()

        finally:
            request_cache.flush_request_cache()
示例#2
0
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()
示例#3
0
    def __call__(self, environ, start_response):

        try:
            # Make sure request-cached values are cleared at start of request
            request_cache.flush_request_cache()

            def gae_bingo_start_response(status, headers, exc_info=None):

                if identity.using_logged_in_bingo_identity():
                    if identity.get_identity_cookie_value():
                        # If using logged in identity, clear cookie b/c we don't need it
                        # and it can cause issues after logging out.
                        headers.append(
                            ("Set-Cookie",
                             identity.delete_identity_cookie_header()))
                else:
                    # Not using logged-in identity. If current identity isn't
                    # already stored in cookie, do it now.
                    if identity.identity(
                    ) != identity.get_identity_cookie_value():
                        headers.append(("Set-Cookie",
                                        identity.set_identity_cookie_header()))

                return start_response(status, headers, exc_info)

            result = self.app(environ, gae_bingo_start_response)
            for value in result:
                yield value

            # Persist any changed GAEBingo data to memcache
            cache.store_if_dirty()

            # If we got a new ID, we should put it to the datastore so it persists
            identity.put_id_if_necessary()

        finally:
            request_cache.flush_request_cache()
示例#4
0
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()
示例#5
0
 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()
示例#6
0
文件: api.py 项目: dguiley/gae_bingo
 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()