Google App Engine: Modifying 1000 entities using TaskQueue

岁酱吖の 提交于 2019-12-11 23:38:27

问题


I am hoping to modify 1000 entities using task queue, as suggested Zig Mandel in my original question here: Google App Engine: Modifying 1000 entities

I have a UserAccount kind like this:

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

Some of the UserAccount emails contain uppercases (example: JohnathanDough@email.com), and I would like to apply email.lower() to every entity's email.

So I've set up a task queue like this:

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)

I have not run this yet, because I want to prevent causing disastrous damage to my data. Should this work?


回答1:


No, in fact this will not do anything at all, because you don't do anything with the lowered email address. You need to actually assign it back to the entity.

account.email = account.email.lower()


来源:https://stackoverflow.com/questions/24761801/google-app-engine-modifying-1000-entities-using-taskqueue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!