What happens when async put results in a competition exception after completing a request in Appengine using NDB?

Using ndb, suppose I put_async'd 40 elements, with @ ndb.toplevel, wrote the result for the user and finished the query, however, one of these put_async would result in a competition exception, would the answer be 500 or 200? Or lets say that if this is a task, will the task be re-performed?

One solution is to get_result () all 40 requests until the request finishes and these exceptions are detected - if they occur - but I'm not sure if this will affect performance.

+5
source share
2 answers

, @ndb.toplevel async . :

@ndb.toplevel. , . , , . https://developers.google.com/appengine/docs/python/ndb/async#intro

, @ndb.toplevel, , async . @ndb.toplevel get_result , ( ). , 500, , , . :

( , ), , . , - :

def get(self):
    deferred.defer(execute_stuff_in_background, param,param1)
    template.render(...)

execute_stuff_in_background puts . , 200.

, , , ( : http://www.youtube.com/watch?v=zSDC_TU7rtc#t=41m35)

: ( 500), , @ndb.toplevel .a > : @alexis , ( put_async , @ndb.toplevel), 500 ( , ). @alexis , , 500, , @ndb.toplevel

+4

, toplevel . , . - ? :

, , .

unittest ( ):

@ndb.tasklet
def raiseSomething():
    yield ndb.Key('foo','bar').get_async()
    raise Exception()

@ndb.toplevel
def callRaiseSomething():
    future = raiseSomething()
    return "hello"

response = callRaiseSomething()
self.assertEqual(response, "hello")

. NDB : " raiseSomething (tests.py:90), Exception()", .

ndb.toplevel RPC, . , get_result(). . "" RPC -, .

, : ( 200)

+3

All Articles