fix: Fixed sometimes missed push in dynamic push
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
import asyncio
|
||||
import time
|
||||
|
||||
from aiohttp import ClientOSError, ServerDisconnectedError
|
||||
from loguru import logger
|
||||
|
||||
from .datasource import DataSource
|
||||
from ..exception import ResponseCodeException, DataSourceException, NetworkException
|
||||
from ..utils import config
|
||||
from ..utils import config, redis
|
||||
from ..utils.network import request
|
||||
from ..utils.utils import get_credential
|
||||
|
||||
@@ -49,18 +48,22 @@ async def dynamic_spider(datasource: DataSource):
|
||||
new_num = latest_dynamic["new_num"]
|
||||
if new_num > 0:
|
||||
logger.debug(f"检测到新动态个数: {new_num}")
|
||||
for i in range(new_num):
|
||||
|
||||
for i in range(new_num + 3):
|
||||
try:
|
||||
detail = latest_dynamic["cards"][i]
|
||||
except IndexError:
|
||||
break
|
||||
|
||||
if int(time.time()) - detail["desc"]["timestamp"] > dynamic_interval:
|
||||
break
|
||||
dynamic_id = detail['desc']['dynamic_id']
|
||||
if await redis.exists_dynamic(dynamic_id):
|
||||
continue
|
||||
await redis.add_dynamic(dynamic_id)
|
||||
|
||||
try:
|
||||
up = datasource.get_up(detail["desc"]["uid"])
|
||||
except DataSourceException:
|
||||
logger.debug(f"不存在于推送配置中的动态: {dynamic_id}, 跳过推送")
|
||||
continue
|
||||
|
||||
task = asyncio.create_task(up.dynamic_update(detail))
|
||||
|
||||
@@ -1179,3 +1179,13 @@ async def add_disable_command(name: str, _id: int):
|
||||
|
||||
async def delete_disable_command(name: str, _id: int):
|
||||
await srem(name, _id)
|
||||
|
||||
|
||||
# 动态
|
||||
|
||||
async def exists_dynamic(_id: int):
|
||||
return await sismember("Dynamics", _id)
|
||||
|
||||
|
||||
async def add_dynamic(_id: int):
|
||||
await sadd("Dynamics", _id)
|
||||
|
||||
Reference in New Issue
Block a user