feat 种子刷新频率控制
This commit is contained in:
parent
c62b29edc4
commit
ed5dec1b0f
@ -1,3 +1,4 @@
|
|||||||
|
from datetime import datetime
|
||||||
from typing import Dict, List, Union
|
from typing import Dict, List, Union
|
||||||
|
|
||||||
from requests import Session
|
from requests import Session
|
||||||
@ -12,6 +13,7 @@ from app.log import logger
|
|||||||
from app.schemas import Notification
|
from app.schemas import Notification
|
||||||
from app.schemas.types import SystemConfigKey, MessageChannel
|
from app.schemas.types import SystemConfigKey, MessageChannel
|
||||||
from app.utils.string import StringUtils
|
from app.utils.string import StringUtils
|
||||||
|
from app.utils.timer import TimerUtils
|
||||||
|
|
||||||
|
|
||||||
class TorrentsChain(ChainBase):
|
class TorrentsChain(ChainBase):
|
||||||
@ -20,6 +22,7 @@ class TorrentsChain(ChainBase):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
_cache_file = "__torrents_cache__"
|
_cache_file = "__torrents_cache__"
|
||||||
|
_last_refresh_time = None
|
||||||
|
|
||||||
def __init__(self, db: Session = None):
|
def __init__(self, db: Session = None):
|
||||||
super().__init__(db)
|
super().__init__(db)
|
||||||
@ -47,6 +50,14 @@ class TorrentsChain(ChainBase):
|
|||||||
"""
|
"""
|
||||||
刷新站点最新资源
|
刷新站点最新资源
|
||||||
"""
|
"""
|
||||||
|
# 控制刷新频率不能小于10分钟
|
||||||
|
if self._last_refresh_time and TimerUtils.diff_minutes(self._last_refresh_time) < 10:
|
||||||
|
logger.warn(f'种子刷新频率过快,跳过本次刷新')
|
||||||
|
return self.get_torrents()
|
||||||
|
|
||||||
|
# 记录刷新时间
|
||||||
|
self._last_refresh_time = datetime.now()
|
||||||
|
|
||||||
# 读取缓存
|
# 读取缓存
|
||||||
torrents_cache = self.get_torrents()
|
torrents_cache = self.get_torrents()
|
||||||
|
|
||||||
|
@ -64,3 +64,13 @@ class TimerUtils:
|
|||||||
time_difference_string += f"{minutes}分钟"
|
time_difference_string += f"{minutes}分钟"
|
||||||
|
|
||||||
return time_difference_string
|
return time_difference_string
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def diff_minutes(input_datetime: datetime) -> int:
|
||||||
|
"""
|
||||||
|
计算当前时间与输入时间的分钟差
|
||||||
|
"""
|
||||||
|
if not input_datetime:
|
||||||
|
return 0
|
||||||
|
time_difference = datetime.datetime.now() - input_datetime
|
||||||
|
return int(time_difference.total_seconds() / 60)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user