From e4b138bc577a92471db0235b91c0b2ffe4057205 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Fri, 4 Aug 2023 09:56:34 +0800 Subject: [PATCH] :bug: Fix task job raise StaleDataError --- plugins/tools/birthday_card.py | 8 ++++++-- plugins/tools/daily_note.py | 16 +++++++++++++--- plugins/tools/sign.py | 6 +++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/plugins/tools/birthday_card.py b/plugins/tools/birthday_card.py index bc8e9163..93a307ca 100644 --- a/plugins/tools/birthday_card.py +++ b/plugins/tools/birthday_card.py @@ -1,9 +1,10 @@ from datetime import datetime from typing import TYPE_CHECKING, List, Optional -from simnet.errors import BadRequest as SimnetBadRequest, RegionNotSupported, InvalidCookies, TimedOut as SimnetTimedOut from simnet.client.routes import Route +from simnet.errors import BadRequest as SimnetBadRequest, RegionNotSupported, InvalidCookies, TimedOut as SimnetTimedOut from simnet.utils.player import recognize_genshin_game_biz, recognize_genshin_server +from sqlalchemy.orm.exc import StaleDataError from telegram.constants import ParseMode from telegram.error import BadRequest, Forbidden @@ -179,4 +180,7 @@ class BirthdayCardSystem(Plugin): continue else: task_db.status = TaskStatusEnum.STATUS_SUCCESS - await self.card_service.update(task_db) + try: + await self.card_service.update(task_db) + except StaleDataError: + logger.warning("用户 user_id[%s] 自动领取生日画片数据过期,跳过更新数据", user_id) diff --git a/plugins/tools/daily_note.py b/plugins/tools/daily_note.py index a30a197a..48c27a66 100644 --- a/plugins/tools/daily_note.py +++ b/plugins/tools/daily_note.py @@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, List, Optional from pydantic import BaseModel, validator from simnet import Region from simnet.errors import BadRequest as SimnetBadRequest, InvalidCookies, TimedOut as SimnetTimedOut +from sqlalchemy.orm.exc import StaleDataError from telegram.constants import ParseMode from telegram.error import BadRequest, Forbidden @@ -222,11 +223,20 @@ class DailyNoteSystem(Plugin): async def update_task_user(self, user: DailyNoteTaskUser): if user.resin_db: - await self.resin_service.update(user.resin_db) + try: + await self.resin_service.update(user.resin_db) + except StaleDataError: + logger.warning("用户 user_id[%s] 自动便签提醒 - 树脂数据过期,跳过更新数据", user.user_id) if user.realm_db: - await self.realm_service.update(user.realm_db) + try: + await self.realm_service.update(user.realm_db) + except StaleDataError: + logger.warning("用户 user_id[%s] 自动便签提醒 - 洞天宝钱数据过期,跳过更新数据", user.user_id) if user.expedition_db: - await self.expedition_service.update(user.expedition_db) + try: + await self.expedition_service.update(user.expedition_db) + except StaleDataError: + logger.warning("用户 user_id[%s] 自动便签提醒 - 探索派遣数据过期,跳过更新数据", user.user_id) @staticmethod async def check_need_note(web_config: WebAppData) -> bool: diff --git a/plugins/tools/sign.py b/plugins/tools/sign.py index bd8c6492..d3fe6bca 100644 --- a/plugins/tools/sign.py +++ b/plugins/tools/sign.py @@ -9,6 +9,7 @@ from httpx import TimeoutException from simnet import Game from simnet.errors import BadRequest as SimnetBadRequest, AlreadyClaimed, InvalidCookies, TimedOut as SimnetTimedOut from simnet.utils.player import recognize_genshin_server +from sqlalchemy.orm.exc import StaleDataError from telegram import InlineKeyboardButton, InlineKeyboardMarkup from telegram.constants import ParseMode from telegram.error import Forbidden, BadRequest @@ -332,4 +333,7 @@ class SignSystem(Plugin): continue else: sign_db.status = TaskStatusEnum.STATUS_SUCCESS - await self.sign_service.update(sign_db) + try: + await self.sign_service.update(sign_db) + except StaleDataError: + logger.warning("用户 user_id[%s] 自动签到数据过期,跳过更新数据", user_id)