【发布时间】:2014-07-15 15:09:46
【问题描述】:
我希望使用任务队列修改 1000 个实体,正如我在原始问题中建议的 Zig Mandel 在这里:Google App Engine: Modifying 1000 entities
我有一个像这样的 UserAccount 类型:
class UserAccount(ndb.Model):
email = ndb.StringProperty()
一些 UserAccount emails 包含大写字母(例如:JohnathanDough@email.com),我想将email.lower() 应用于每个实体的电子邮件。
所以我设置了一个这样的任务队列:
class LowerEmailQueue(BaseHandler):
def get(self):
all_accounts = UserAccount.query().fetch()
for a in all_accounts:
taskqueue.add(url = '/lower-email', params = {'account_id': a.key.id()})
class LowerEmail(BaseHandler):
def post(self):
account_id = self.request.get('account_id')
account = UserAccount.get_by_id(int(account_id))
account.email = account.email.lower()
account.put()
app = webapp2.WSGIApplication([
('/', MainPage),
('/lower-email-queue', LowerEmailQueue),
('/lower-email', LowerEmail),
], debug=True)
我还没有运行它,因为我想防止对我的数据造成灾难性的破坏。这应该工作吗?
【问题讨论】:
标签: python google-app-engine app-engine-ndb task-queue