示例#1
0
    async def _start_game_times_import(self, game_ids: List[str]) -> None:
        if self._game_times_import_in_progress:
            raise ImportInProgress()

        context = await self.prepare_game_times_context(game_ids)

        async def import_game_time(game_id, context_):
            try:
                game_time = await self.get_game_time(game_id, context_)
                self._game_time_import_success(game_time)
            except ApplicationError as error:
                self._game_time_import_failure(game_id, error)
            except Exception:
                logging.exception(
                    "Unexpected exception raised in import_game_time")
                self._game_time_import_failure(game_id, UnknownError())

        async def import_game_times(game_ids_, context_):
            try:
                imports = [
                    import_game_time(game_id, context_)
                    for game_id in game_ids_
                ]
                await asyncio.gather(*imports)
            finally:
                self._game_times_import_finished()
                self._game_times_import_in_progress = False
                self.game_times_import_complete()

        self._external_task_manager.create_task(import_game_times(
            game_ids, context),
                                                "game times import",
                                                handle_exceptions=False)
        self._game_times_import_in_progress = True
示例#2
0
    async def _start_achievements_import(self, game_ids: List[str]) -> None:
        if self._achievements_import_in_progress:
            raise ImportInProgress()

        context = await self.prepare_achievements_context(game_ids)

        async def import_game_achievements(game_id, context_):
            try:
                achievements = await self.get_unlocked_achievements(
                    game_id, context_)
                self._game_achievements_import_success(game_id, achievements)
            except ApplicationError as error:
                self._game_achievements_import_failure(game_id, error)
            except Exception:
                logging.exception(
                    "Unexpected exception raised in import_game_achievements")
                self._game_achievements_import_failure(game_id, UnknownError())

        async def import_games_achievements(game_ids_, context_):
            try:
                imports = [
                    import_game_achievements(game_id, context_)
                    for game_id in game_ids_
                ]
                await asyncio.gather(*imports)
            finally:
                self._achievements_import_finished()
                self._achievements_import_in_progress = False
                self.achievements_import_complete()

        self.create_task(import_games_achievements(game_ids, context),
                         "Games unlocked achievements import")
        self._achievements_import_in_progress = True
    async def _start_user_presence_import(self, user_ids: List[str]) -> None:
        if self._user_presence_import_in_progress:
            raise ImportInProgress()

        context = await self.prepare_user_presence_context(user_ids)

        async def import_user_presence(user_id, context_) -> None:
            try:
                self._user_presence_import_success(
                    user_id, await self.get_user_presence(user_id, context_))
            except ApplicationError as error:
                self._user_presence_import_failure(user_id, error)
            except Exception:
                logging.exception(
                    "Unexpected exception raised in import_user_presence")
                self._user_presence_import_failure(user_id, UnknownError())

        async def import_user_presence_set(user_ids_, context_) -> None:
            try:
                await asyncio.gather(*[
                    import_user_presence(user_id, context_)
                    for user_id in user_ids_
                ])
            finally:
                self._user_presence_import_finished()
                self._user_presence_import_in_progress = False
                self.user_presence_import_complete()

        self._external_task_manager.create_task(import_user_presence_set(
            user_ids, context),
                                                "user presence import",
                                                handle_exceptions=False)
        self._user_presence_import_in_progress = True
async def test_game_time_import_failure(plugin, write):
    plugin.game_time_import_failure("134", ImportInProgress())
    response = json.loads(write.call_args[0][0])

    assert response == {
        "jsonrpc": "2.0",
        "method": "game_time_import_failure",
        "params": {
            "game_id": "134",
            "error": {
                "code": 600,
                "message": "Import already in progress"
            }
        }
    }
示例#5
0
    async def start(self, ids):
        if self._import_in_progress:
            raise ImportInProgress()

        self._import_in_progress = True
        try:
            context = await self._prepare_context(ids)
            self._task_manager.create_task(
                self._import_elements(ids, context),
                "{} import".format(self._name),
                handle_exceptions=False
            )
        except:
            self._import_in_progress = False
            raise
    async def start_game_times_import(self, game_ids: List[str]):
        """Starts the task of importing game times
        This method is called by the GOG Galaxy Client.

        :param game_ids: ids of the games for which the game time is imported
        """
        if self._game_times_import_in_progress:
            raise ImportInProgress()

        async def import_game_times_task(game_ids):
            try:
                await self.import_game_times(game_ids)
            finally:
                self.game_times_import_finished()
                self._game_times_import_in_progress = False

        asyncio.create_task(import_game_times_task(game_ids))
        self._game_times_import_in_progress = True
示例#7
0
    async def start(self, ids):
        if self._import_in_progress:
            raise ImportInProgress()

        async def import_element(id_, context_):
            try:
                element = await self._get(id_, context_)
                self._notification_success(id_, element)
            except ApplicationError as error:
                self._notification_failure(id_, error)
            except asyncio.CancelledError:
                pass
            except Exception:
                logger.exception("Unexpected exception raised in %s importer",
                                 self._name)
                self._notification_failure(id_, UnknownError())

        async def import_elements(ids_, context_):
            try:
                imports = [import_element(id_, context_) for id_ in ids_]
                await asyncio.gather(*imports)
                self._notification_finished()
                self._complete()
            except asyncio.CancelledError:
                logger.debug("Importing %s cancelled", self._name)
            finally:
                self._import_in_progress = False

        self._import_in_progress = True
        try:
            context = await self._prepare_context(ids)
            self._task_manager.create_task(import_elements(ids, context),
                                           "{} import".format(self._name),
                                           handle_exceptions=False)
        except:
            self._import_in_progress = False
            raise