GAE/P – schedule downtime for maintenance

Question:

I’m doing some refactoring of my entities and I’d like to temporarily shut down all access to my app engine app (except for admin) to prevent users modifying any entities while I am performing the maintenance.

What is a straightforward way to do this? The only easy way I can think of is to create a new app.yaml file where admin is required for all pages. One downside to this is that I wouldn’t be able to give users a friendly message that access will be restored soon.

Any better ways of doing this?

Answers:

Use the Admin Console’s Application Settings tab “Disable Datastore Writes”: https://developers.google.com/appengine/docs/adminconsole/applicationsettings#Disable_Datastore_Writes

This sets your datastore to read-only mode and prevents any users from making changes.

EDIT: Here’s a good write-up on how to modify your app to gracefully degrade during downtime: https://developers.google.com/appengine/docs/python/howto/maintenance

Answered By: Sologoub

I’ve created a maintenance mode by modifying the WSGIApplication.

My main.py now looks like this:

import webapp2
import views

maintenance_mode = False

# These routes need to be always available
routes = [
    # Static pages
    (r'/(|about|contact|help|faq|terms|privacy|users|methods)', 
     views.Static),
    # Other routes that should always be available here
]

if maintenance_mode:
    routes += [(r'/.*', views.Maintenance)] # Displays a maintenance message
    application = webapp2.WSGIApplication(routes)

else:
    routes += [
        # Routes that are not available in maintenance mode
    ]
    application = webapp2.WSGIApplication(routes)

views.py has the following:

class Maintenance(webapp2.RequestHandler):
    def get(self):
        self.response.write (
            "My app is down for maintenance and should be back up shortly.")
    def post(self):
        self.response.write (
            "My app is down for maintenance and should be back up shortly.")

This seems like an easy and safe solution, but please let me know if you seen any flaws in this approach.