fix: Fixed sometimes missed push in dynamic push

This commit is contained in:
LWR
2023-05-20 22:22:53 +08:00
parent d7ec1325c4
commit e2dbef8739
2 changed files with 18 additions and 5 deletions
+8 -5
View File
@@ -1,12 +1,11 @@
import asyncio import asyncio
import time
from aiohttp import ClientOSError, ServerDisconnectedError from aiohttp import ClientOSError, ServerDisconnectedError
from loguru import logger from loguru import logger
from .datasource import DataSource from .datasource import DataSource
from ..exception import ResponseCodeException, DataSourceException, NetworkException from ..exception import ResponseCodeException, DataSourceException, NetworkException
from ..utils import config from ..utils import config, redis
from ..utils.network import request from ..utils.network import request
from ..utils.utils import get_credential from ..utils.utils import get_credential
@@ -49,18 +48,22 @@ async def dynamic_spider(datasource: DataSource):
new_num = latest_dynamic["new_num"] new_num = latest_dynamic["new_num"]
if new_num > 0: if new_num > 0:
logger.debug(f"检测到新动态个数: {new_num}") logger.debug(f"检测到新动态个数: {new_num}")
for i in range(new_num):
for i in range(new_num + 3):
try: try:
detail = latest_dynamic["cards"][i] detail = latest_dynamic["cards"][i]
except IndexError: except IndexError:
break break
if int(time.time()) - detail["desc"]["timestamp"] > dynamic_interval: dynamic_id = detail['desc']['dynamic_id']
break if await redis.exists_dynamic(dynamic_id):
continue
await redis.add_dynamic(dynamic_id)
try: try:
up = datasource.get_up(detail["desc"]["uid"]) up = datasource.get_up(detail["desc"]["uid"])
except DataSourceException: except DataSourceException:
logger.debug(f"不存在于推送配置中的动态: {dynamic_id}, 跳过推送")
continue continue
task = asyncio.create_task(up.dynamic_update(detail)) task = asyncio.create_task(up.dynamic_update(detail))
+10
View File
@@ -1179,3 +1179,13 @@ async def add_disable_command(name: str, _id: int):
async def delete_disable_command(name: str, _id: int): async def delete_disable_command(name: str, _id: int):
await srem(name, _id) 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)