def run_peer_server_as_process_and_stub( port, radiostation_port=conf.PORT_RADIOSTATION, group_id=None, score=None, timeout=None, wait=True): if timeout is None: timeout = conf.TIMEOUT_FOR_PEER_INIT process = run_peer_server_as_process(port, radiostation_port, group_id, score) async def _wait(): StubCollection().amqp_target = conf.AMQP_TARGET StubCollection().amqp_key = f"{util.get_private_ip()}:{port}" logging.debug(f'{StubCollection().amqp_key} peer hello') await StubCollection().create_peer_stub() await StubCollection().peer_stub.async_task().hello() logging.debug(f'{StubCollection().amqp_key} peer hello complete') if wait: loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) try: future = asyncio.ensure_future(_wait()) loop.run_until_complete(future) loop.stop() loop.close() except Exception as e: logging.warning(f"Exception in loop : {e}") stub, channel = util.get_stub_to_server(target='localhost:' + str(port), stub_class=loopchain_pb2_grpc.PeerServiceStub, time_out_seconds=timeout) return process, stub
def run_radio_station_as_process_and_stub(port, timeout=None): if timeout is None: timeout = conf.TIMEOUT_FOR_RS_INIT process = run_radio_station_as_process(port) stub, channel = util.get_stub_to_server(target='localhost:' + str(port), stub_class=loopchain_pb2_grpc.RadioStationStub, time_out_seconds=timeout) return process, stub
def run_radio_station_as_process_and_stub(port): process = run_radio_station_as_process(port) stub, channel = util.get_stub_to_server( target=f"localhost:{port}", stub_class=loopchain_pb2_grpc.RadioStationStub) return process, stub
def __make_stub(self, is_stub_reuse=True): if util.datetime_diff_in_mins(self.__stub_update_time) >= conf.STUB_REUSE_TIMEOUT or \ not is_stub_reuse or self.__stub is None: util.logger.spam(f"StubManager:__make_stub is_stub_reuse({is_stub_reuse}) self.__stub({self.__stub})") self.__stub, self.__channel = util.get_stub_to_server( self.__target, self.__stub_type, is_check_status=False, ssl_auth_type=self.__ssl_auth_type) self.__stub_update_time = datetime.datetime.now() if self.__stub: self.__update_last_succeed_time() else: pass
def __make_stub(self, is_stub_reuse=True): if util.datetime_diff_in_mins(self.__stub_update_time) >= conf.STUB_REUSE_TIMEOUT or \ not is_stub_reuse or self.__stub is None: self.__stub = util.get_stub_to_server(self.__target, self.__stub_type, is_check_status=False) # if self.__is_secure: # # TODO need treat to secure channel but not yet # channel = grpc.insecure_channel(self.__target) # else: # channel = grpc.insecure_channel(self.__target) # # self.__stub = self.__stub_type(channel) self.__stub_update_time = datetime.datetime.now() else: pass