示例#1
0
文件: emit.py 项目: 1-Hash/lymph
    def run(self):
        event_type = self.args.get("<event-type>")
        body = json.loads(self.args.get("<body>"))

        trace.set_id(self.args.get("--trace-id"))
        client = Client.from_config(self.config)
        client.emit(event_type, body)
示例#2
0
 def dispatch_request(self, request):
     trace.set_id()
     urls = self.url_map.bind_to_environ(request.environ)
     request.urls = urls
     try:
         endpoint, args = urls.match()
         if callable(endpoint):
             handler = endpoint(self, request)
             response = handler.dispatch(args)
         else:
             try:
                 handler = getattr(self, endpoint)
             except AttributeError:
                 raise  # FIXME
             response = handler(request, **args)
     except HTTPException as e:
         response = e.get_response(request.environ)
     except Exception as e:
         if hasattr(e, 'to_http_response'):
             response = e.to_http_response(request.environ)
         else:
             if not self.container.debug:
                 logger.exception('uncaught exception')
             exc_info = sys.exc_info()
             try:
                 self.container.error_hook(exc_info)
             except:
                 logger.exception('error hook failure')
             finally:
                 del exc_info
             if self.container.debug:
                 raise
             response = Response('', status=500)
     return response
示例#3
0
文件: emit.py 项目: torte/lymph
    def run(self):
        event_type = self.args.get('<event-type>')
        body = json.loads(self.args.get('<body>'))

        trace.set_id(self.args.get('--trace-id'))
        client = Client.from_config(self.config)
        client.emit(event_type, body)
示例#4
0
文件: demo.py 项目: torte/lymph
 def loop(self):
     i = 0
     while True:
         gevent.sleep(self.delay)
         trace.set_id()
         try:
             result = self.echo.upper(text='foo_%s' % i)
         except lymph.RpcError:
             continue
         print("result = %s" % result)
         i += 1
示例#5
0
 def loop(self):
     i = 0
     echo = self.proxy('lymph://echo', timeout=2)
     while True:
         gevent.sleep(.1)
         trace.set_id()
         try:
             result = echo.upper(text='foo_%s' % i)
         except lymph.RpcError:
             continue
         print("result = %s" % result)
         i += 1
示例#6
0
文件: rpc.py 项目: alazaro/lymph
 def recv_message(self, msg):
     trace.set_id(msg.headers.get('trace_id'))
     logger.debug('<- %s', msg)
     connection = self.connect(msg.source)
     connection.on_recv(msg)
     if msg.is_request():
         self.spawn(self.dispatch_request, msg)
     elif msg.is_reply():
         try:
             channel = self.channels[msg.subject]
         except KeyError:
             logger.debug('reply to unknown subject: %s (msg-id=%s)', msg.subject, msg.id)
             return
         channel.recv(msg)
     else:
         logger.warning('unknown message type: %s (msg-id=%s)', msg.type, msg.id)
示例#7
0
 def dispatch_request(self, request):
     trace.set_id()
     logger.info('%s %s', request.method, request.path)
     urls = self.url_map.bind_to_environ(request.environ)
     request.urls = urls
     try:
         rule, kwargs = request.urls.match(method=request.method, return_rule=True)
     except NotFound:
         response = self.NotFound().get_response(request.environ)
     except MethodNotAllowed:
         response = self.MethodNotAllowed().get_response(request.environ)
     except HTTPException as ex:
         response = ex.get_response(request.environ)
     else:
         response = self.handle(request, rule, kwargs)
     response.headers['X-Trace-Id'] = trace.get_id()
     return response
示例#8
0
 def dispatch_request(self, request):
     trace.set_id()
     logger.info('%s %s', request.method, request.path)
     urls = self.url_map.bind_to_environ(request.environ)
     request.urls = urls
     try:
         rule, kwargs = request.urls.match(method=request.method, return_rule=True)
     except NotFound:
         response = self.NotFound().get_response(request.environ)
     except MethodNotAllowed:
         response = self.MethodNotAllowed().get_response(request.environ)
     except HTTPException as ex:
         response = ex.get_response(request.environ)
     else:
         response = self.handle(request, rule, kwargs)
     response.headers['X-Trace-Id'] = trace.get_id()
     return response
示例#9
0
 def recv_message(self, msg):
     trace.set_id(msg.headers.get('trace_id'))
     logger.debug('<- %s %r', msg, msg.headers)
     connection = self.connect(msg.source)
     connection.on_recv(msg)
     if msg.is_request():
         self.spawn(self.dispatch_request, msg)
     elif msg.is_reply():
         try:
             channel = self.channels[msg.subject]
         except KeyError:
             logger.debug('reply to unknown subject: %s (msg-id=%s)',
                          msg.subject, msg.id)
             return
         channel.recv(msg)
     else:
         logger.warning('unknown message type: %s (msg-id=%s)', msg.type,
                        msg.id)
示例#10
0
 def dispatch_request(self, request):
     trace.set_id()
     urls = self.url_map.bind_to_environ(request.environ)
     request.urls = urls
     try:
         endpoint, args = urls.match()
         if callable(endpoint):
             handler = endpoint(self, request)
             response = handler.dispatch(args)
         else:
             try:
                 handler = getattr(self, endpoint)
             except AttributeError:
                 raise  # FIXME
             response = handler(request, **args)
     except HTTPException as e:
         response = e.get_response(request.environ)
     return response
示例#11
0
 def dispatch_request(self, request):
     trace.set_id()
     urls = self.url_map.bind_to_environ(request.environ)
     request.urls = urls
     try:
         endpoint, args = urls.match()
         if callable(endpoint):
             handler = endpoint(self, request)
             response = handler.dispatch(args)
         else:
             try:
                 handler = getattr(self, endpoint)
             except AttributeError:
                 raise  # FIXME
             response = handler(request, **args)
     except HTTPException as e:
         response = e.get_response(request.environ)
     return response
示例#12
0
文件: interfaces.py 项目: netme/lymph
 def dispatch_request(self, request):
     if self.request_trace_id_header:
         trace_id = request.headers.get(self.request_trace_id_header)
     else:
         trace_id = None
     trace.set_id(trace_id)
     logger.info("%s %s", request.method, request.path)
     urls = self.url_map.bind_to_environ(request.environ)
     request.urls = urls
     try:
         rule, kwargs = request.urls.match(method=request.method, return_rule=True)
     except NotFound:
         response = self.NotFound().get_response(request.environ)
     except MethodNotAllowed:
         response = self.MethodNotAllowed().get_response(request.environ)
     except HTTPException as ex:
         response = ex.get_response(request.environ)
     else:
         response = self.handle(request, rule, kwargs)
     response.headers[self.response_trace_id_header] = trace.get_id()
     return response
示例#13
0
文件: interfaces.py 项目: torte/lymph
 def dispatch_request(self, request):
     trace.set_id()
     logger.info('%s %s', request.method, request.path)
     urls = self.url_map.bind_to_environ(request.environ)
     request.urls = urls
     try:
         rule, kwargs = request.urls.match(return_rule=True)
         self.container.http_request_hook(request, rule, kwargs)
         handler = self.get_handler(request, rule)
         if hasattr(handler, "dispatch"):
             response = handler.dispatch(kwargs)
         else:
             response = handler(request, **kwargs)
     except HTTPException as e:
         response = e.get_response(request.environ)
     except Exception as e:
         if hasattr(e, 'to_http_response'):
             response = e.to_http_response(request.environ)
         else:
             if not self.container.debug:
                 logger.exception('uncaught exception')
             exc_info = sys.exc_info()
             extra_info = {
                 'url': request.url,
                 'trace_id': trace.get_id(),
                 'interface': self.__class__.__name__,
             }
             try:
                 self.container.error_hook(exc_info, extra=extra_info)
             except:
                 logger.exception('error hook failure')
             finally:
                 del exc_info
             if self.container.debug:
                 raise
             response = Response('', status=500)
     response.headers['X-Trace-Id'] = trace.get_id()
     return response
示例#14
0
 def dispatch_request(self, request):
     trace.set_id()
     logger.info('%s %s', request.method, request.path)
     urls = self.url_map.bind_to_environ(request.environ)
     request.urls = urls
     try:
         rule, kwargs = request.urls.match(return_rule=True)
         self.container.http_request_hook(request, rule, kwargs)
         handler = self.get_handler(request, rule)
         if hasattr(handler, "dispatch"):
             response = handler.dispatch(kwargs)
         else:
             response = handler(request, **kwargs)
     except HTTPException as e:
         response = e.get_response(request.environ)
     except Exception as e:
         if hasattr(e, 'to_http_response'):
             response = e.to_http_response(request.environ)
         else:
             if not self.container.debug:
                 logger.exception('uncaught exception')
             exc_info = sys.exc_info()
             extra_info = {
                 'url': request.url,
                 'trace_id': trace.get_id(),
                 'interface': self.__class__.__name__,
             }
             try:
                 self.container.error_hook(exc_info, extra=extra_info)
             except:
                 logger.exception('error hook failure')
             finally:
                 del exc_info
             if self.container.debug:
                 raise
             response = Response('', status=500)
     response.headers['X-Trace-Id'] = trace.get_id()
     return response
示例#15
0
文件: events.py 项目: TimBeyer/lymph
 def __call__(self, event, *args, **kwargs):
     trace.set_id(event.headers.get('trace_id'))
     logger.debug('<E %s', event)
     return self.func(self.interface, event, *args, **kwargs)
示例#16
0
文件: request.py 项目: itakouna/lymph
 def request():
     trace.set_id(self.args.get('--trace-id'))
     return client.request(address, subject, body, timeout=timeout)
示例#17
0
 def __call__(self, event, *args, **kwargs):
     trace.set_id(event.headers.get('trace_id'))
     logger.debug('<E %s', event)
     return self.func(self.interface, event, *args, **kwargs)
示例#18
0
 def get_trace_id_from_request():
     if self.request_trace_id_header is not None:
         trace.set_id(flask_current_request.get(self.request_trace_id_header))
示例#19
0
 def request():
     trace.set_id(self.args.get('--trace-id'))
     return client.request(address, subject, body, timeout=timeout)