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

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

问题描述

我希望使用任务队列修改1000个实体,就像我在这里提出的原始问题中的Zig Mandel: Google App Engine:修改1000个实体



我有 UserAccount 种像这样:

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

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

所以我设置了一个这样的任务队列:

  class LowerEmailQueue(BaseHandler):

def get(self):
all_accounts = UserAccount.query()。fetch()
for all_accounts:
taskqueue.add(url ='/ lower-email',params = { 交流count_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)

我还没有执行此操作,因为我想防止对我的数据造成灾难性的损害。这应该工作吗?

解决方案

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

  account.email = account.email.lower()


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?

解决方案

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天全站免登陆