Google App Engine:使用 TaskQueue 修改 1000 个实体 [英] Google App Engine: Modifying 1000 entities using TaskQueue

查看:20
本文介绍了Google App Engine:使用 TaskQueue 修改 1000 个实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我有一个这样的 UserAccount:

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

某些 UserAccount email 包含大写字母(例如:JohnathanDough@email.com),我想将 email.lower() 应用于每个实体的电子邮件.

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?

推荐答案

不,实际上这根本不会做任何事情,因为您不会对降低的电子邮件地址做任何事情.您需要实际将其分配回实体.

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()

这篇关于Google App Engine:使用 TaskQueue 修改 1000 个实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆