App Engine SDK DevServer Read-Only Mode?

2020-06-01 10:21发布

Is there a way to run the app engine dev server in read-only mode in order to simulate the scheduled maintenance by Google which puts the datastore into read-only mode?

Gracefully Degrading During Scheduled Maintenance

1条回答
爷、活的狠高调
2楼-- · 2020-06-01 10:51

I wish there was a checkbox that would make the datastore read-only. This hack seems to do what I need. Put the following in your main handler:

from google.appengine.runtime.apiproxy_errors import CapabilityDisabledError
from google.appengine.api import apiproxy_stub_map

def make_datastore_readonly():
  """Throw ReadOnlyError on put and delete operations."""
  def hook(service, call, request, response):
    assert(service == 'datastore_v3')
    if call in ('Put', 'Delete'):
      raise CapabilityDisabledError('Datastore is in read-only mode')
  apiproxy_stub_map.apiproxy.GetPreCallHooks().Push('readonly_datastore', hook, 'datastore_v3')

def main():
  make_datastore_readonly()

It was found here: http://groups.google.com/group/google-appengine/msg/51db9d51401715ca

查看更多
登录 后发表回答