googleappengine:使用TaskQueu修改1000个实体

2024-09-28 22:32:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望使用任务队列修改1000个实体,正如我在这里的原始问题中Zig Mandel所建议的:Google App Engine: Modifying 1000 entities

我有这样一个用户帐户:

class UserAccount(ndb.Model):
    email = ndb.StringProperty()

一些UserAccountemail包含大写字母(例如: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)

我还没有运行这个,因为我想防止对我的数据造成灾难性的破坏。这样行吗?你知道吗


Tags: self实体idget队列emaildefaccount