def handle_result(self, handler): if self.get_status() == TIMEOUT: # timeout, ignore return response = handler.response # DON'T do_filter here, it blocks select loop if response.code >= 700: if response.code == 702: status = TIMEOUT else: status = NETERR else: status = NORMAL result = Result(self.id, status, response, self.ident) cakey = response.request.get_cache_key() if self.cachefs and cakey and response.max_age: self.cachefs.save(cakey, response.get_header("content-type"), response.content, response.max_age, 0) handler.callback = None handler.response = None self.set_status(status, result) tuple_cb(self, self.callback)
def handle_result (self, request): if self.get_status () == TIMEOUT: # timeout, ignore return status = NORMAL if request.expt: reason = str (request.expt) if reason == "Operation Timeout": status = TIMEOUT elif reason == "Socket Panic": status = NETERR result = task.Result (self.id, status, request, self.ident) self.set_status (status, result) tuple_cb (self, self.callback)
def handle_result(self, request): if self.get_status() == TIMEOUT: # timeout, ignore return if request.expt_class: if request.expt_str == "Operation Timeout": status = TIMEOUT else: status = NETERR else: status = NORMAL result = cluster_dist_call.Result(self.id, status, request, self.ident) self.set_status(status, result) tuple_cb(self, self.callback)
def _build_request(self, method, params): # For Django QuerySet and SQLGen if hasattr(params[0], "query"): params = (str(params[0].query), ) + params[1:] self._cached_request_args = (method, params) # backup for retry if self._use_cache and rcache.the_rcache: self._cached_result = rcache.the_rcache.get( self._get_ident(), self._use_cache) if self._cached_result is not None: self._callback and tuple_cb(self._cached_result, self._callback) return while self._avails(): asyncon = self._get_connection(None) rs = Dispatcher(self._cv, asyncon.address, ident=not self._mapreduce and self._get_ident() or None, filterfunc=self._filter, callback=self._collect) self._requests[rs] = asyncon req = request.Request(self.dbtype, self.server, self.dbname, self.auth, method, params, rs.handle_result, self._meta) asyncon.execute(req) self._request = req # sample for unitest trigger.wakeup() return self
def handle_callback(self): tuple_cb(self, self.callback)
def _do_callback(self, callback): result = self.dispatch(wait=False) tuple_cb(result, callback)
def _build_request(self, method, params): self._cached_request_args = (method, params) # backup for retry if self._use_cache and rcache.the_rcache: self._cached_result = rcache.the_rcache.get( self._get_ident(), self._use_cache) if self._cached_result is not None: self._cached_result.meta = self._meta self._callback and tuple_cb(self._cached_result, self._callback) return else: self._use_cache = False requests = 0 while self._avails(): if self._cluster.get_name() != "__socketpool__": asyncon = self._get_connection(None) else: asyncon = self._get_connection(self._uri) self._auth = self._auth or asyncon.get_auth() _reqtype = self._reqtype.lower() rs = Dispatcher(self._cv, asyncon.address, ident=not self._mapreduce and self._get_ident() or None, filterfunc=self._filter, cachefs=self._cachefs, callback=self._collect) self._requests[rs] = asyncon args = (params, self._headers, self._auth, self._logger, self._meta) try: if _reqtype in ("ws", "wss"): handler = ws_request_handler.RequestHandler request = ws_request.Request(self._uri, *args) else: if not self._use_cache: self._add_header("Cache-Control", "no-cache") handler = http_request_handler.RequestHandler try: class_ = self.proto_map[_reqtype] except KeyError: if _reqtype == "upload": request = http_request.HTTPMultipartRequest( self._uri, _reqtype, *args) else: request = http_request.HTTPRequest( self._uri, _reqtype, *args) else: request = class_(self._uri, method, *args) requests += self._handle_request(request, rs, asyncon, handler) except: self._logger("Request Creating Failed", "fail") self._logger.trace() rs.request_failed() asyncon.set_active(False) continue if requests: self._request = request # sample for unitest trigger.wakeup() if _reqtype[-3:] == "rpc": return self
def request_failed(self): self.status = REQFAIL tuple_cb(self, self.callback)
def set_callback(self, callback, reqid=None, timeout=10): if reqid is not None: self.result.meta["__reqid"] = reqid tuple_cb(self.result, callback)
def handle_callback(self): if self.callbacked: return tuple_cb(self, self.callback) self.callbacked = 1