English ▼
Skip to page content Skip to main navigation
e.g. "templates" or "datastore"

# Gracefully Degrading During Scheduled Maintenance

Scheduled maintenance periods are a reality of any web service available 24/7/365 and App Engine applications are no exception. To make these periods as short as possible, App Engine provides special exceptions to inform applications so that they may handle the maintenance period gracefully.

- Working with a Read-only Datastore
- Handling Memcache

## Working with a Read-only Datastore

During scheduled maintenance, the datastore will often be put into read-only mode allowing data to be read by the application, but no new data can be stored and no existing data can be modified. During this period, all datastore writes and transactions will throw an exception. Your application can detect these errors and indicate to the user that the application is in read-only, recommending that they try again later.

To modify your app to adapt, you will need to catch the relevant Python exception: `google.appengine.runtime.apiproxy_errors.CapabilityDisabledError`. This will be thrown by db.Model.put(), db.Model.delete(), and db.run_in_transaction(). You can use Python's try syntax to fail gracefully on writes like this:

      from google.appengine.ext import db
      from google.appengine.runtime.apiproxy_errors import CapabilityDisabledError
      myModel = db.Model()
      try:
          myModel.put()
      except CapabilityDisabledError:
          # fail gracefully here
          pass

## Handling Memcache

The Memcache service is also disabled during a maintenance period. This should not impact the experience directly, only the performance of the application as nothing will be cached.

During a read-only maintenance period, calls to the memcache API will not throw exceptions but will instead return False for set() calls and None for get() calls (just like any other cache miss). In addition, memcache API calls will return immediately during this period, without any additional latency.