Ejemplo n.º 1
0
    def __get_release_info(self,
                           hub_uuid: str,
                           app_id: list,
                           use_cache=True) -> list or None:
        if use_cache:
            # 尝试取缓存
            try:
                return cache_manager.get_release_cache(hub_uuid, app_id)
            except (KeyError, NameError):
                pass

        # 获取云端数据
        cache_data = False
        release_info = None
        try:
            hub = self.__hub_server_manager.get_hub(hub_uuid)
            release_info = hub.get_release_info(app_id)
            cache_data = True
        except HTTPError as e:
            status_code = e.response.status_code
            if status_code == 404:
                logging.warning(f"""app_info: {app_id}
HTTP CODE 404 ERROR: {e}""")
                cache_data = True
        except Exception as e:
            logging.error(f"""app_info: {app_id}
ERROR: {e}""")
            if debug_mode:
                raise e
        # 缓存数据,包括 404 None 数据
        if cache_data:
            cache_manager.add_release_cache(hub_uuid, app_id, release_info)
        return release_info
Ejemplo n.º 2
0
 def GetAppStatusList(self, request, context) -> ResponseList:
     try:
         request = MessageToDict(request, preserving_proto_field_name=True)
         hub_uuid: str = request["hub_uuid"]
         app_id_list: list = [item['app_id'] for item in request["app_id_list"]]
         return self.__get_app_status_list(hub_uuid, app_id_list)
     except Exception:
         logging.error(traceback.format_exc())
         return None
Ejemplo n.º 3
0
 def GetAppStatus(self, request, context) -> AppStatus:
     try:
         request = MessageToDict(request, preserving_proto_field_name=True)
         hub_uuid: str = request['hub_uuid']
         app_id: list = request['app_id']
         return self.__get_app_status(hub_uuid, app_id)
     except Exception:
         logging.error(traceback.format_exc())
         return None
Ejemplo n.º 4
0
 def GetDownloadInfo(self, request, context) -> DownloadInfo:
     try:
         request = MessageToDict(request, preserving_proto_field_name=True)
         app_id_info = request["app_id_info"]
         hub_uuid = app_id_info["hub_uuid"]
         app_id = app_id_info["app_id"]
         asset_index = request["asset_index"]
         return self.__get_download_info(hub_uuid, app_id, asset_index)
     except Exception:
         logging.error(traceback.format_exc())
         return None
Ejemplo n.º 5
0
 def get_download_info(self, hub_uuid: str, app_id: list,
                       asset_index: list) -> dict or None:
     if hub_uuid not in hub_dict:
         logging.warning(f"NO HUB: {hub_uuid}")
         return None
     hub = self.__hub_server_manager.get_hub(hub_uuid)
     try:
         return hub.get_download_info(app_id, asset_index)
     except Exception as e:
         logging.error(f"""app_info: {app_id}
 ERROR: {e}""")
         return None
Ejemplo n.º 6
0
    def get_release_cache(self, hub_uuid: str, app_info: list) -> dict or None:
        key = self.__get_app_cache_key(hub_uuid, app_info)
        if key is None:
            logging.error(f"""WRONG FORMAT
hub_uuid: {hub_uuid}
app_info: {app_info}""")
            raise NameError
        if self.__redis_release_cache_client.exists(key) == 0:
            raise KeyError
        release_info = self.__redis_release_cache_client.get(key)
        logging.debug(f"release cached: {app_info}")
        return json.loads(release_info)