def OnPageMapSuccess(pagemapfuturekey): pagemapfuture = GetFutureAndCheckReady(pagemapfuturekey) placeholderfuture = GetFutureAndCheckReady(placeholderfuturekey) future = GetFutureAndCheckReady(futurekey) result = pagemapfuture.get_result() placeholderfuture.set_success(result) future.set_success(result)
def completion(): lmemcacheClient2 = memcache.Client() try: lreentry = _get_memcount(lmemcacheClient1, "reentry") logging.info("reentry=%s" % lreentry) if (lreentry or 0) > 0: raise PermanentTaskFailure("Reentry == %s, should be 0" % lreentry) _set_memcount(lmemcacheClient2, "reentry", 1) time.sleep(5) lnumCalls = _get_memcount(lmemcacheClient1, "numcalls") lnumCalls = (lnumCalls or 0) + 1 logging.info("lnumCalls=%s" % lnumCalls) if lnumCalls == 1: fut = GetFutureAndCheckReady(futurekey) fut.set_success("called completion once") if lnumCalls > 1: raise PermanentTaskFailure("Called too many times (%s)" % lnumCalls) _set_memcount(lmemcacheClient1, "numcalls", lnumCalls) finally: _set_memcount(lmemcacheClient2, "reentry", 0)
def Tick(aProgress): fut = GetFutureAndCheckReady(futurekey) fut.set_localprogress(aProgress * 5) if aProgress < 20: Tick(aProgress + 1) else: fut.set_success(aProgress)
def OnCountSuccess(countfuturekey): countfuture = GetFutureAndCheckReady(countfuturekey) futureobj = GetFutureAndCheckReady(futurekey) count = countfuture.get_result() placeholderfuture = placeholderfuturekey.get() if placeholderfuture: placeholderfuture.set_weight(count * 2) futureobj.set_weight(count * 2) futurendbshardedpagemap(pagemapf, ndbquery, pagesize, onsuccessf=OnPageMapSuccess, weight=count, parentkey=placeholderfuturekey, **taskkwargs) # now that the second pass is actually constructed and running, we can let the placeholder accept a result. placeholderfuture.set_readyforesult()
def onprogress(futurekey): futureobj = GetFutureAndCheckReady(futurekey) if futureobj: lrun = lrunKey.get() if lrun and lrun.status in [ _TEST_RUN_STATUS_NOT_READY, _TEST_RUN_STATUS_READY ]: lrun.progress = futureobj.get_calculatedprogress() lrun.put()
def onsuccess(futurekey): futureobj = GetFutureAndCheckReady(futurekey) lrun = lrunKey.get() if lrun and lrun.status in [ _TEST_RUN_STATUS_NOT_READY, _TEST_RUN_STATUS_READY ]: lrun.status = _TEST_RUN_STATUS_PASS lrun.progress = 100 lresult = futureobj.get_result() if lresult: lrun.final_message = str(lresult) lrun.final_runtime_usec = calc_final_runtime_usec(lrun.started) lrun.put()
def onfailure(futurekey): futureobj = GetFutureAndCheckReady(futurekey) lrun = lrunKey.get() if lrun and lrun.status in [ _TEST_RUN_STATUS_NOT_READY, _TEST_RUN_STATUS_READY ]: lrun.status = _TEST_RUN_STATUS_FAIL lrun.progress = 100 try: futureobj.get_result() except Exception, ex: lrun.final_message = str(ex) lrun.final_runtime_usec = calc_final_runtime_usec(lrun.started) lrun.put()
def completion(): fut = GetFutureAndCheckReady(futurekey) fut.set_success("called completion")
def SetResult(): fut = GetFutureAndCheckReady(futurekey) fut.set_success(True)