Пример #1
0
def _async_run(handler, request, callback, frame):
    tik = time.time()
    response = protocol.Response.to(request)
    try:
        klass = request.klass
        method = request.method
        args = request.args
        kwargs = request.kwargs
        expire_at = request.expire_at
        call_at = request.call_at
        if WASTE_GAP and tik - call_at > WASTE_GAP:
            # 设置WASTE_GAP意味着被调用请求到收到请求耗时超过WASTE_GAP秒,则不处理了
            Log.get_logger().debug('[abandon] mid: %s call_at: hands_on_at: %f',
                                   response.mid, request.call_at, tik)
            return
        func = handler.get_ref(klass, method, args, kwargs)
        res = func()
        tok = time.time()
        costs = tok - tik
        response.set_result(res)
        response.set_costs(costs)

        if tok > expire_at > 0:
            Log.get_logger().debug('[timeout] mid: %s call_at: %f expire_at: %f hands_on_at: %f done_at: %f costs: %f',
                                   response.mid, request.call_at, request.expire_at, tik, tok, costs)
            return
        Log.get_logger().debug('[response] mid: %s status: %d costs: %f', response.mid, response.status, costs)
    except Exception as e:
        tok = time.time()
        costs = tok - tik
        response.set_error(e)
        response.set_costs(costs)
        Log.get_logger().exception(e)
    frame.append(response.box())
    IOLoop.instance().add_callback(callback, frame)
Пример #2
0
 def deploy(self):
     if not self._ioloop.is_running():
         with self._lock:
             if not self._ioloop.is_running():
                 threading.Thread(
                     target=lambda: IOLoop.instance().start()).start()
     self._deployed = True
Пример #3
0
def _async_run(handler, request, callback, frame):
    tik = time.time()
    response = protocol.Response.to(request)
    try:
        klass = request.klass
        method = request.method
        args = request.args
        kwargs = request.kwargs
        expire_at = request.expire_at
        call_at = request.call_at
        if WASTE_GAP and tik - call_at > WASTE_GAP:
            # 设置WASTE_GAP意味着被调用请求到收到请求耗时超过WASTE_GAP秒,则不处理了
            Log.get_logger().debug(
                '[abandon] mid: %s call_at: hands_on_at: %f', response.mid,
                request.call_at, tik)
            return
        func = handler.get_ref(klass, method, args, kwargs)
        res = func()
        tok = time.time()
        costs = tok - tik
        response.set_result(res)
        response.set_costs(costs)

        if tok > expire_at > 0:
            Log.get_logger().debug(
                '[timeout] mid: %s call_at: %f expire_at: %f hands_on_at: %f done_at: %f costs: %f',
                response.mid, request.call_at, request.expire_at, tik, tok,
                costs)
            return
        Log.get_logger().debug('[response] mid: %s status: %d costs: %f',
                               response.mid, response.status, costs)
    except Exception as e:
        tok = time.time()
        costs = tok - tik
        response.set_error(e)
        response.set_costs(costs)
        Log.get_logger().exception(e)
    frame.append(response.box())
    IOLoop.instance().add_callback(callback, frame)
Пример #4
0
 def __init__(self, host, port, configs={}):
     self.host = host
     self.port = port
     self.configs = configs
     self._deployed = False
     self._monitored = False
     self._lock = threading.Lock()
     self._rpclient = AsyncRPCClient()
     self._supervisor = Supervisor()
     self.event = zmq.EVENT_CONNECTED | zmq.EVENT_DISCONNECTED
     for config, value in self.configs.iteritems():
         self._rpclient.sock().setsockopt(config, value)
     self._rpclient.connect('tcp://{host}:{port}'.format(host=self.host, port=self.port))
     self._ioloop = IOLoop.instance()
Пример #5
0
 def __init__(self, host, port, configs={}):
     self.host = host
     self.port = port
     self.configs = configs
     self._deployed = False
     self._monitored = False
     self._lock = threading.Lock()
     self._rpclient = AsyncRPCClient()
     self._supervisor = Supervisor()
     self.event = zmq.EVENT_CONNECTED | zmq.EVENT_DISCONNECTED
     for config, value in self.configs.iteritems():
         self._rpclient.sock().setsockopt(config, value)
     self._rpclient.connect('tcp://{host}:{port}'.format(host=self.host,
                                                         port=self.port))
     self._ioloop = IOLoop.instance()
Пример #6
0
 def __init__(self):
     super(Supervisor, self).__init__()
     self.flag = zmq.POLLIN
     self._visor = self.ctx.socket(zmq.PAIR)
     IOLoop.instance().add_handler(self)
Пример #7
0
 def __init__(self):
     super(Supervisor, self).__init__()
     self.flag = zmq.POLLIN
     self._visor = self.ctx.socket(zmq.PAIR)
     IOLoop.instance().add_handler(self)
Пример #8
0
 def deploy(self):
     if not self._ioloop.is_running():
         with self._lock:
             if not self._ioloop.is_running():
                 threading.Thread(target=lambda: IOLoop.instance().start()).start()
     self._deployed = True