Kel*_*ler 6 python migration schema google-app-engine google-cloud-datastore
首先,这是我在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:
break
keys = None
while not keys:
try:
keys = db.put(batch)
except db.Timeout:
logging.warn("Put timed out, retrying")
last_key = keys[-1]
print "Updated %d records" % (len(keys),)
Run Code Online (Sandbox Code Playgroud)
奇怪的是,代码适用于具有100到1,000个实例的类,并且脚本通常需要大约10秒.但是当我尝试在数据库中运行类似于100K实例的类的代码时,脚本运行30秒,然后我收到:
"错误:服务器错误
服务器遇到错误,无法完成您的请求.如果问题仍然存在,请报告您的问题并提及此错误消息以及导致该问题的查询.""
知道为什么GAE在三十秒后超时了吗?我该怎么做才能解决这个问题?
谢谢!凯勒
你正在通过它的声音击中第二个DeadlineExceededError.AppEngine请求每个只能运行30秒.当引发DeadLineExceedError时,你的工作是停止处理并在你的时间用完时整理,下次它被提升时你无法捕捉它.
您应该查看使用Mapper API将迁移拆分为批处理并使用任务队列运行每个批处理.
| 归档时间: |
|
| 查看次数: |
926 次 |
| 最近记录: |