🐛 Fix task job raise StaleDataError

This commit is contained in:
xtaodada 2023-08-04 09:56:34 +08:00
parent 865f29bd77
commit e4b138bc57
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
3 changed files with 24 additions and 6 deletions

View File

@ -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)

View File

@ -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:

View File

@ -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)