为什么Google App Engine任务可能会被虚假地执行多次? [英] Why Google App Engine Tasks can spuriously be executed more than once?

查看:129
本文介绍了为什么Google App Engine任务可能会被虚假地执行多次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么Google App Engine任务可以多次执行?
根据来自Google I / O 2009的Brett Slatkin讲话 ,即使没有服务器故障,任务也可能会虚假地运行两次!

Why Google App Engine Tasks can be executed more than once? According do Brett Slatkin talk from Google I/O 2009, it is possible for a task to spuriously run twice even without server failures!

这与虚假的线程唤醒有关?

This has something to do with spurious wakeup of threads?

推荐答案

Brant Slatkin给了 2010年I / 0类似演讲

Brant Slatkin gave a similar talk at I/0 2010.

我不知道他曾经详细说明过会发生什么或什么时候发生。他的观点是,由于任务队列的工作方式,可以通过设计将任务重新排队。因此,您需要编写任务,以避免发生问题。

I don't know that he ever gave details of how or when this could happen. His point was that because of the way Task Queues work it is possible by design for tasks to be reenqueued. Because of this you need to write your tasks so that it does not cause problems if that happens.

例如,假设您有一项任务发送电子邮件,然后增加数据存储中的计数器。如果代码中存在错误或数据存储已关闭,则可能会成功发送电子邮件,但写入数据存储失败。如果您未通过处理异常来处理数据存储中的数据存储故障,则写入数据存储失败将导致您的任务返回HTTP状态代码500.任务队列被设计为在任务返回状态代码时重新排队> 299。这会导致您的任务反复执行,直到写入数据存储成功为止。这意味着有人会得到许多重复的电子邮件。

For example, let's say you have a task that sends an email and then increments a counter in Datastore. If there was a bug in your code OR if Datastore was down, it is possible for the email to be sent successfully but for the write to Datastore to fail. If you didn't handle the failure from Datastore in your code by handling the exception the failure to write to Datastore would result in your task returning a HTTP status code of 500. Task Queue is designed to reenqueue the task if it returns a status code >299. This would result in your task being executed over and over until the write to datastore was successful. Which means that someone would get many duplicate emails.

我认为关于可能为一个任务虚假地运行两次..这句话只是一种说App Engine不能保证不会发生这种情况,所以你需要确保你在代码中处理它。

I think the line about "Possible for a task to spuriously run twice.." was just a way to say App Engine isn't guaranteed to protect against this so you need to make sure you take care of it in your code.

这篇关于为什么Google App Engine任务可能会被虚假地执行多次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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