Created
November 26, 2014 09:47
-
-
Save erlichmen/98d6dfa50e56a22958eb to your computer and use it in GitHub Desktop.
Detecting new instance creation at runtime on Google App Engine
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
current_instance_id = None | |
def is_loading_request_wsgi_middleware(app): | |
import logging | |
def is_loading_request_wsgi_middleware_wrapper(environ, start_response): | |
global current_instance_id | |
if current_instance_id != environ.get('INSTANCE_ID'): | |
current_instance_id = environ.get('INSTANCE_ID') | |
logging.info("new instance loaded %s", current_instance_id) | |
return app(environ, start_response) | |
return is_loading_request_wsgi_middleware_wrapper | |
def webapp_add_wsgi_middleware(app): | |
app = is_loading_request_wsgi_middleware(app) | |
return app |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment