Is nnb async guaranteed to execute after the application request is complete?

I use ndb to write a profiling model that logs some data on an application request. Each request calls the ndb request ndb.put_async to register data, while the client does not care about the result. In fact, I do not want the application request to expect statistics to be saved for profiling.

However, I was confused by the explanation from the official documentation. If the application request completed before the ndb request was completed, will the ndb request be completed? The documentation indicates that

if the request handler exists too early, this may not happen

What are the criteria for this to happen? Does this mean that regardless of whether the user cares about the results, future.get_result needs to be called anyway to make sure the ndb request is complete?

The source documentation ( https://developers.google.com/appengine/docs/python/ndb/async ) says:

In this example, it's a little silly to call future.get_result: the application never uses the result from NDB. This code is located there so that the request handler does not exit before NDB has supplied the finishing materials; if the request handler exits too soon, it happens. As a convenience, you can decorate the @ Ndb.toplevel request handler. This means that the handler should not exit until asynchronous requests are completed. This, in turn, allows you to send a request and not worry about the result.

+7
source share
2 answers

If the application request completed before the ndb request was completed, will the ndb request be completed?

Not.

Does this mean that regardless of whether the user needs to take care of the results, future.get_result needs to be called anyway, just to make sure the ndb request is complete?

In principle, yes, but you can use the ndb.toplevel decorator for convenience so that you do not have to wait for the result explicitly. However, I do not think that this is what you want.

Perhaps taskqueue is what you want. Please check it.

+7
source

Thanks for the clarification. What about generic RPC (non-NDB) - for example incr_async () in memcache.Client ()? Noting that this is a very fast RPC call, is it guaranteed that the RPC will complete?

Ie, which of the following is true:

(a) there is something in the infrastructure that will wait for all known RPCs until the request is completed

(b) the request will be completed and the async RPC will also be completed regardless of when the request is completed

(c) RPCs in flight formally canceled

(d) something else?

+1
source

All Articles