From e21d7224861ead016ddc21f861ef4cf4875b24fb Mon Sep 17 00:00:00 2001 From: xtaodada Date: Fri, 4 Aug 2023 10:00:30 +0800 Subject: [PATCH] :bug: Fix task job raise StaleDataError --- plugins/tools/daily_note.py | 11 +++++++++-- plugins/tools/sign.py | 6 +++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/plugins/tools/daily_note.py b/plugins/tools/daily_note.py index cf3710e..1acde29 100644 --- a/plugins/tools/daily_note.py +++ b/plugins/tools/daily_note.py @@ -5,6 +5,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 @@ -182,9 +183,15 @@ 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.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 a1a0931..8c9519d 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_starrail_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)