I have a Google App engine application that I want to work differently depending upon if it is running in my 开发者_StackOverflow社区local dev environment (i.e. with dev_appserver.py) as against running in actual GAE cloud.
Currently I use a flag variable that I manually toggle to achieve that. But I am sure one day I will forget to change it and will lead to problem. So I would like to know if there is an API or some other way to figure out where the GAE app is actually running?
Thanks.
You could check the SERVER_SOFTWARE environment variable to see if it is Development/X or Google App Engine/X:
http://code.google.com/appengine/docs/python/runtime.html#The_Environment
I know the original question was for python, but to do this for Java use:
if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Production) {
// running on prod
} else {
// running on dev
}
I use the datastore.get() to pull values.
On the dev_appserver, the datastore contains an entity "Environment" set to "local". On the GAE dev app, "Environment" is "dev" On the GAE prod app, "Environment" is "prod"
You can extend to UAT, etc.
精彩评论