首先,这是我在Stack Overflow上的第一篇文章,所以请原谅任何新的错误步骤.如果我可以更清楚地描述我的问题,请告诉我.
我在Google App Engine上运行了一个大型应用程序,并且一直在添加新功能,这些功能迫使我修改旧数据类并添加新数据类.为了清理我们的数据库并更新旧条目,我一直在尝试编写一个脚本,它可以遍历类的实例,进行更改,然后重新保存它们.问题是,当您拨打服务器的时间超过几秒钟时,Google App Engine会超时.
几个星期以来,我一直在努力解决这个问题.我找到的最佳解决方案是:http://code.google.com/p/rietveld/source/browse/trunk/update_entities.py?specl = vsvn427&r = 427
我为自己的网站创建了该代码的一个版本,您可以在此处看到:
def schema_migration (self, target, batch_size=1000):
last_key = None
calls = {"Affiliate": Affiliate, "IPN": IPN, "Mail": Mail, "Payment": Payment, "Promotion": Promotion}
while True:
q = calls[target].all()
if last_key:
q.filter('__key__ >', last_key)
q.order('__key__')
this_batch_size = batch_size
while True:
try:
batch = q.fetch(this_batch_size)
break
except (db.Timeout, DeadlineExceededError):
logging.warn("Query timed out, retrying")
if this_batch_size == 1:
logging.critical("Unable to update entities, aborting")
return
this_batch_size //= 2
if not batch: …Run Code Online (Sandbox Code Playgroud) python migration schema google-app-engine google-cloud-datastore