Tag Archives: gae

How to manage Google AppEngine maintenance periods

AppEngine logoHere is a small snippet of code that I use on applications deployed on Google AppEngine to inform users that the application is in maintenance mode.

It usually happen when the AppEngine team put the datastore in read-only mode for maintenance purpose but other capabilities can be tested as well.

def requires_datastore_write(view):
    def newview(request, *args, **kwargs):
        from google.appengine.api import capabilities
        datastore_write_enabled = capabilities.CapabilitySet('datastore_v3', capabilities=['write']).is_enabled()

        if datastore_write_enabled:
            return view(request, *args, **kwargs)
        else:
            from django.shortcuts import render_to_response
            from django.template import RequestContext
            return render_to_response('maintenance.html', context_instance=RequestContext(request))

    return newview

This is a python decorator and you can use it to decorate views that require write access to the datastore. For example:

@requires_datastore_write
def update(request):
    # Do something that requires to write in the database

You will need to create a Django template named maintenance.html to display a warning to your users. Mine looks like this:

<h2>Application Maintenance</h2>
<p>The LibraryThing for Facebook application is currently
in maintenance mode and some operations are temporarily unavailable.</p>
<p>Thanks for trying back later. Sorry for the inconvenience.</p>

I Can Haz Java?

They announced it yesterday at the Google Campfire ’09 (here and here) and it is today on the Google App Engine blog: Java is now supported on Google App Engine!

It comes with a set of Eclipse plugins to test and deploy Java servlets, using JDO or JPA to support database access. Of course, the database behind this is BigTable, which means that a lot of relational features are not available, but it scales!

Go there to get you started, or, if you want to know if your preferred framework will play well with GAE, go to the “Will it play in App Engine” page.

That’s good news! Especially because we may start having more and more Java applications outside of the corporate walls.

Yes Google, YES!