def _run(): try: call_def_in_loop_return_result(__run(), __loop) logging.info("gRPC 已脱离阻塞") except KeyboardInterrupt: logging.info("停止 gRPC") stop()
def _init_account_debug(hub_uuid: str, account: dict): logging.info(f"开始测试:hub_uuid: {hub_uuid}, account: {json.dumps(account)}") logging.info("测试 init_account 函数") row_download_info = init_account(hub_uuid, account) js = json.dumps(row_download_info, sort_keys=True, indent=4, ensure_ascii=False) logging.debug(js)
async def __run_core(aw, item_num: int): if item_num > 5: timeout = item_num * 11.25 else: timeout = 30 try: await asyncio.wait_for(aw, timeout=timeout) except asyncio.TimeoutError: logging.info(f'aw: {aw} timeout!')
def __get_cloud_config_version(request) -> bool: dev_version = False # noinspection PyBroadException try: request = MessageToDict(request, preserving_proto_field_name=True) if request["s"] == "dev": dev_version = True logging.info("使用 Dev 分支的云端配置仓库") except Exception: logging.info("使用 Master 分支的云端配置仓库") pass return dev_version
def refresh_cache(self, uuid: str or None = None): i = 0 logging.info("refresh all data: start") cache_queue = cache_manager.cached_app_queue for hub_uuid in cache_queue.keys(): if uuid and hub_uuid != uuid: continue release_iter = self.get_release(hub_uuid, cache_queue[hub_uuid], use_cache=False) if release_iter: for _ in release_iter: i += 1 logging.info(f"refresh all data: finish({i})")
def __get_def_google_play(self, use_spare=False) -> _GooglePlayAPI: if use_spare: logging.warn("GooglePlay: Use Spare Aurora API") email, token = _get_aurora_token(1) else: email, token = _get_aurora_token(0) api = self.__init_google_play_by_email_and_token(email, token) add_tmp_cache( _auth_cache_key, json.dumps({ "gsfId": api.gsfId, "ac2dmToken": api.authSubToken })) logging.info("GooglePlay: Renew Auth") return api
def __get_def_google_play(self, random=False) -> _GooglePlayAPI: position = 0 if random: # logging.warn("GooglePlay: Try Random Aurora API") position = -1 email, token = _get_aurora_token(position) api = self.__init_google_play_by_email_and_token(email, token) add_tmp_cache( _auth_cache_key, json.dumps({ "gsfId": api.gsfId, "ac2dmToken": api.authSubToken })) logging.info("GooglePlay: Renew Auth") return api
async def __run(): global __server await __lock.acquire() __server = aio.server( ThreadPoolExecutor(max_workers=server_config.max_workers)) route_pb2_grpc.add_UpdateServerRouteServicer_to_server(Greeter(), __server) __server.add_insecure_port(f'{server_config.host}:{server_config.port}') logging.info("gRPC 启动中") await __server.start() logging.info("gRPC 已启动") # 等待停止信号 logging.info("启动 gRPC 进程运行阻塞锁(额外)") await __lock.acquire() logging.info("脱离 gRPC 进程运行阻塞锁(额外)") await __server.wait_for_termination() logging.info("脱离 gRPC 运行阻塞")
def GetCloudConfig(self, request, context) -> Str: rule_hub_url = None # noinspection PyBroadException try: request = MessageToDict(request, preserving_proto_field_name=True) if request["s"] == "dev": rule_hub_url = "https://raw.githubusercontent.com/DUpdateSystem/UpgradeAll-rules/" \ "dev/rules/rules.json" logging.info("使用 Dev 分支的云端配置仓库") except Exception: pass if rule_hub_url is None: rule_hub_url = server_config.cloud_rule_hub_url response = get_response(rule_hub_url) if response: logging.info("已完成获取云端配置仓库数据请求") return Str(s=response.text)
def run(): server = None try: checker_thread.start() server, server_thread, debug_thread = __run() if debug_thread: debug_thread.join() server.stop(5).wait() if server_thread: server_thread.join() except KeyboardInterrupt: logging.info("正在停止") finally: checker_thread.shutdown() if server: server.stop(5).wait() logging.info("已停止") sys.exit(0)
def run(): server_process = None try: checker_thread.start() server_process, debug_thread = __run() if debug_thread: debug_thread.join() web_getter_manager.stop() if server_process: #start_schedule() server_process.join() web_getter_manager.join() except KeyboardInterrupt: logging.info("正在停止") web_getter_manager.stop() stop() finally: checker_thread.shutdown() if server_process: server_process.kill() logging.info("已停止") sys.exit(0)
def _standard_debug(hub_uuid: str, auth: dict, app_id: dict): logging.info( f"开始测试:hub_uuid: {hub_uuid}, app_id: {json.dumps(app_id)}, auth: {json.dumps(auth)}" ) logging.info("测试 get_app_status 函数") for release_dict in get_release_dict(hub_uuid, auth, [app_id], use_cache=False, cache_data=False): js = json.dumps(release_dict, sort_keys=True, indent=4, ensure_ascii=False) logging.debug(js) logging.info("测试 get_download_info 函数") row_download_info = get_download_info_list(hub_uuid, auth, app_id, [0, 0]) js = json.dumps(row_download_info, sort_keys=True, indent=4, ensure_ascii=False) logging.debug(js)
def _auto_refresh(): logging.info("auto refresh data: start") data_manager.refresh_cache() logging.info("auto refresh data: finish")
async def __stop(): logging.info("gRPC 停止中") await __server.stop(5) logging.info("gRPC 已停止") __lock.release() logging.info("已取消 gRPC 进程运行阻塞锁(额外)")