def _on_rpc_done(rpc_id: int, future: grpc.Future, method: str, print_response: bool) -> None: exception = future.exception() hostname = "" _global_rpc_statuses[method][future.code().value[0]] += 1 if exception is not None: with _global_lock: _global_rpcs_failed[method] += 1 if exception.code() == grpc.StatusCode.DEADLINE_EXCEEDED: logger.error(f"RPC {rpc_id} timed out") else: logger.error(exception) else: response = future.result() hostname = None for metadatum in future.initial_metadata(): if metadatum[0] == "hostname": hostname = metadatum[1] break else: hostname = response.hostname if future.code() == grpc.StatusCode.OK: with _global_lock: _global_rpcs_succeeded[method] += 1 else: with _global_lock: _global_rpcs_failed[method] += 1 if print_response: if future.code() == grpc.StatusCode.OK: logger.debug("Successful response.") else: logger.debug(f"RPC failed: {call}") with _global_lock: for watcher in _watchers: watcher.on_rpc_complete(rpc_id, hostname, method)
def _on_rpc_done(rpc_id: int, future: grpc.Future, print_response: bool) -> None: exception = future.exception() hostname = "" if exception is not None: if exception.code() == grpc.StatusCode.DEADLINE_EXCEEDED: logger.error(f"RPC {rpc_id} timed out") else: logger.error(exception) else: response = future.result() logger.info(f"Got result {rpc_id}") hostname = response.hostname if print_response: if future.code() == grpc.StatusCode.OK: logger.info("Successful response.") else: logger.info(f"RPC failed: {call}") with _global_lock: for watcher in _watchers: watcher.on_rpc_complete(rpc_id, hostname)