任务队列和非幂等任务
我正在开发一个投票应用程序,用户可以在其中上传所有选民的电子邮件地址列表。进行一些错误检查后,我为每个选民创建一个 Voter
实体。由于可能有大量投票者,我在任务队列中创建 Voter
实体以避免 30 秒的限制,任务如下所示:
put_list = []
for email, id in itertools.izip(voter_emails, uuids):
put_list.append(Voter(election = election,
email = email,
uuid = id))
election.txt_voters = ""
put_list.append(election)
db.put(put_list)
但是,此任务不是幂等的。有没有办法使这个任务幂等?或者有更好的方法来做到这一点吗?
I'm working on a voting app, where the user can upload a list of email addresses for all of the voters. After doing some error checking, I create a Voter
entity for each voter. Since there can be a large number of voters, I create the Voter
entities in a taskqueue to avoid the 30 second limit and the task looks like this:
put_list = []
for email, id in itertools.izip(voter_emails, uuids):
put_list.append(Voter(election = election,
email = email,
uuid = id))
election.txt_voters = ""
put_list.append(election)
db.put(put_list)
This task, however, isn't idempotent. Is there a way to make this task idempotent? Or is there a better way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 key_name 而不是 uuid 属性来防止创建重复的选民实体。
use a key_name rather than a uuid property to prevent creating duplicate voter entities.