关于Google App Engine:是否可以确保在应用程序请求完成后执行ndb async?

Is ndb async guaranteed to execute after application request has finished?

我正在使用ndb编写一个分析模型,该模型记录每个应用程序请求的一些数据。每个请求都通过ndb.put_async调用一个ndb请求来记录数据,而客户端并不关心结果。本质上,我不希望应用程序请求等待保存统计数据以进行概要分析。

但是,我对官方文档中的解释感到困惑。如果应用程序请求在ndb请求完成之前已经完成,那么是否仍可以保证ndb请求完成?该文档指出

if the request handler exists too early, the put might never happen

在什么条件下会发生这种情况?这是否意味着无论用户是否关心结果,都必须调用future.get_result才能确保执行了ndb请求?

原始文档(https://developers.google.com/appengine/docs/python/ndb/async)说:

In this example, it's a little silly to call future.get_result: the
application never uses the result from NDB. That code is just in there
to make sure that the request handler doesn't exit before the NDB put
finishes; if the request handler exits too early, the put might never
happen. As a convenience, you can decorate the request handler with
@ndb.toplevel. This tells the handler not to exit until its
asynchronous requests have finished. This in turn lets you send off
the request and not worry about the result.


If an application request has finished before the ndb request finishes, would the ndb request still be guaranteed to finish?

编号

Does this mean that regardless of whether a user care about the result, future.get_result needs to be called anyway just to make sure the ndb request is performed?

基本上可以,但是为了方便起见,可以使用ndb.toplevel装饰器,这样您就不必显式等待结果。就是说,我认为这不是您想要的。

可能是您想要的任务队列。请检查一下。


感谢您的澄清。普通的RPC(非NDB)怎么样-例如memcache.Client()中的incr_async()?抛开这是一个非常非常快速的RPC调用,是否可以保证RPC将完成?

即,以下哪一项是正确的:

(a)基础结构中有一些东西会在完成请求之前等待所有已知的RPC

(b)无论请求何时完成,请求都将完成,异步RPC也将完成

(c)飞行中的RPC被正式取消

(d)还有其他东西吗?