为什么 Google App Engine 任务可以被多次虚假执行?

发布于 2024-10-02 08:06:50 字数 249 浏览 3 评论 0原文

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

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

糖果控 2024-10-09 08:06:50

Brant Slatkin 在 I/0 2010 上的类似演讲

我不知道他是否详细说明过这种情况如何或何时发生。他的观点是,由于任务队列的工作方式,任务可以重新排队。因此,您需要编写任务,以便在发生这种情况时不会导致问题。

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

我认为关于“一个任务可能会虚假运行两次..”的说法只是说明 App Engine 不能保证防止这种情况发生,因此您需要确保在代码中处理好它。

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.

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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文