def _send(self, msg, headers=None, **kwargs): # could have a specified timeout in kwargs if 'timeout' in kwargs and kwargs['timeout'] is not None: timeout = kwargs['timeout'] else: timeout = CFG.endpoint.receive.timeout or 10 log.debug("RequestEndpointUnit.send (timeout: %s)", timeout) if not self._recv_greenlet: self.channel.setup_listener(NameTrio(self.channel._send_name.exchange)) # anon queue self.channel.start_consume() self.spawn_listener() self.response_queue = event.AsyncResult() self.message_received = lambda m, h: self.response_queue.set((m, h)) BidirectionalEndpointUnit._send(self, msg, headers=headers) try: result_data, result_headers = self.response_queue.get(timeout=timeout) except Timeout: raise exception.Timeout('Request timed out (%d sec) waiting for response from %s' % (timeout, str(self.channel._send_name))) log.debug("Got response to our request: %s, headers: %s", result_data, result_headers) return result_data, result_headers
def _es_call(es, *args, **kwargs): res = AsyncResult() def async_call(es, *args, **kwargs): res.set(es(*args,**kwargs)) spawn(async_call,es,*args,**kwargs) try: retval = res.get(timeout=CFG.get_safe('server.elasticsearch.timeout', 10)) except Timeout: raise exceptions.Timeout("Call to ElasticSearch timed out.") return retval
def _send(self, msg, headers=None, **kwargs): # could have a specified timeout in kwargs if 'timeout' in kwargs and kwargs['timeout'] is not None: timeout = kwargs['timeout'] else: timeout = CFG.endpoint.receive.timeout or 10 log.debug("RequestEndpointUnit.send (timeout: %s)", timeout) ts = time.time() if not self._recv_greenlet: self.channel.setup_listener( NameTrio(self.channel._send_name.exchange)) # anon queue self.channel.start_consume() self.spawn_listener() self.response_queue = event.AsyncResult() self.message_received = lambda m, h: self.response_queue.set((m, h)) BidirectionalEndpointUnit._send(self, msg, headers=headers) try: result_data, result_headers = self.response_queue.get( timeout=timeout) except Timeout: raise exception.Timeout( 'Request timed out (%d sec) waiting for response from %s' % (timeout, str(self.channel._send_name))) finally: elapsed = time.time() - ts log.info( "Client-side request (conv id: %s/%s, dest: %s): %.2f elapsed", headers.get('conv-id', 'NOCONVID'), headers.get('conv-seq', 'NOSEQ'), self.channel._send_name, elapsed) log.debug("Response data: %s, headers: %s", result_data, result_headers) return result_data, result_headers