🐛 Fix task job raise StaleDataError

This commit is contained in:
xtaodada 2023-08-04 10:00:30 +08:00
parent b1141c65b8
commit e21d722486
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
2 changed files with 14 additions and 3 deletions

View File

@ -5,6 +5,7 @@ from typing import TYPE_CHECKING, List, Optional
from pydantic import BaseModel, validator from pydantic import BaseModel, validator
from simnet import Region from simnet import Region
from simnet.errors import BadRequest as SimnetBadRequest, InvalidCookies, TimedOut as SimnetTimedOut from simnet.errors import BadRequest as SimnetBadRequest, InvalidCookies, TimedOut as SimnetTimedOut
from sqlalchemy.orm.exc import StaleDataError
from telegram.constants import ParseMode from telegram.constants import ParseMode
from telegram.error import BadRequest, Forbidden from telegram.error import BadRequest, Forbidden
@ -182,9 +183,15 @@ class DailyNoteSystem(Plugin):
async def update_task_user(self, user: DailyNoteTaskUser): async def update_task_user(self, user: DailyNoteTaskUser):
if user.resin_db: 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: 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 @staticmethod
async def check_need_note(web_config: WebAppData) -> bool: async def check_need_note(web_config: WebAppData) -> bool:

View File

@ -9,6 +9,7 @@ from httpx import TimeoutException
from simnet import Game from simnet import Game
from simnet.errors import BadRequest as SimnetBadRequest, AlreadyClaimed, InvalidCookies, TimedOut as SimnetTimedOut from simnet.errors import BadRequest as SimnetBadRequest, AlreadyClaimed, InvalidCookies, TimedOut as SimnetTimedOut
from simnet.utils.player import recognize_starrail_server from simnet.utils.player import recognize_starrail_server
from sqlalchemy.orm.exc import StaleDataError
from telegram import InlineKeyboardButton, InlineKeyboardMarkup from telegram import InlineKeyboardButton, InlineKeyboardMarkup
from telegram.constants import ParseMode from telegram.constants import ParseMode
from telegram.error import Forbidden, BadRequest from telegram.error import Forbidden, BadRequest
@ -332,4 +333,7 @@ class SignSystem(Plugin):
continue continue
else: else:
sign_db.status = TaskStatusEnum.STATUS_SUCCESS 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)