type: 收敛测试 schemas 与协议层类型
This commit is contained in:
@@ -21,7 +21,12 @@ from ..models import (
|
||||
DouyuXpdGoodsSnapshot,
|
||||
ProxyConfig as ProxyConfigModel,
|
||||
)
|
||||
from .douyu_service import DOUYU_CONFIG_FIELDS, douyu_config_value, ensure_douyu_config, douyu_task_payload
|
||||
from .douyu_service import (
|
||||
DOUYU_CONFIG_FIELDS,
|
||||
douyu_config_value,
|
||||
ensure_douyu_config,
|
||||
douyu_task_payload,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .douyu_runner import DouyuBatchRunner
|
||||
@@ -78,7 +83,9 @@ class DouyuBatchRunnerCore:
|
||||
self._proxy_fetcher = self._create_proxy_fetcher()
|
||||
self._static_proxies = self._resolve_static_proxies()
|
||||
if self._static_proxies:
|
||||
logger.info(f"[douyu] 写操作任务将走静态代理: {self._static_proxies.get('https', '')}")
|
||||
logger.info(
|
||||
f"[douyu] 写操作任务将走静态代理: {self._static_proxies.get('https', '')}"
|
||||
)
|
||||
elif self._proxy_fetcher:
|
||||
logger.info("[douyu] 写操作任务将按任务从代理 API 取新代理")
|
||||
|
||||
@@ -89,7 +96,11 @@ class DouyuBatchRunnerCore:
|
||||
return None
|
||||
wl_platform = getattr(cfg, "whitelist_platform", None) or "xiequ"
|
||||
wl_credentials = getattr(cfg, "whitelist_credentials", None)
|
||||
if not wl_credentials and getattr(cfg, "whitelist_uid", "") and getattr(cfg, "whitelist_ukey", ""):
|
||||
if (
|
||||
not wl_credentials
|
||||
and getattr(cfg, "whitelist_uid", "")
|
||||
and getattr(cfg, "whitelist_ukey", "")
|
||||
):
|
||||
wl_credentials = {"uid": cfg.whitelist_uid, "ukey": cfg.whitelist_ukey}
|
||||
return ProxyFetcher(
|
||||
api_url=cfg.api_url,
|
||||
@@ -267,8 +278,7 @@ class DouyuBatchRunnerCore:
|
||||
"""同步和平小店商品快照,移除上一次热门抢购等遗留商品。"""
|
||||
now = datetime.now(timezone.utc)
|
||||
commodity_ids = {
|
||||
str(raw.get("commodity_id") or raw.get("iGoodsId") or "")
|
||||
for raw in goods
|
||||
str(raw.get("commodity_id") or raw.get("iGoodsId") or "") for raw in goods
|
||||
}
|
||||
commodity_ids.discard("")
|
||||
query = db.query(DouyuXpdGoodsSnapshot)
|
||||
@@ -304,11 +314,15 @@ class DouyuBatchRunnerCore:
|
||||
|
||||
def _config_info(self, db: Session) -> dict:
|
||||
config = ensure_douyu_config(db)
|
||||
return {field: douyu_config_value(field, getattr(config, field, None)) for field in DOUYU_CONFIG_FIELDS}
|
||||
return {
|
||||
field: douyu_config_value(field, getattr(config, field, None))
|
||||
for field in DOUYU_CONFIG_FIELDS
|
||||
}
|
||||
|
||||
def _task_payload(self, task: DouyuTask) -> dict:
|
||||
result = task.result if isinstance(task.result, dict) else {}
|
||||
payload = result.get("payload") if isinstance(result.get("payload"), dict) else {}
|
||||
payload_raw = result.get("payload")
|
||||
payload = payload_raw if isinstance(payload_raw, dict) else {}
|
||||
return {**payload, **self.payload}
|
||||
|
||||
def _client(self, cookie: str) -> DouyuActivityClient:
|
||||
@@ -338,8 +352,13 @@ class DouyuBatchRegistry:
|
||||
def __init__(self):
|
||||
self._batches: dict[str, dict] = {}
|
||||
|
||||
def register(self, batch_id: str, log_queue: asyncio.Queue,
|
||||
loop: asyncio.AbstractEventLoop, runner: DouyuBatchRunner):
|
||||
def register(
|
||||
self,
|
||||
batch_id: str,
|
||||
log_queue: asyncio.Queue,
|
||||
loop: asyncio.AbstractEventLoop,
|
||||
runner: DouyuBatchRunner,
|
||||
):
|
||||
self._batches[batch_id] = {
|
||||
"log_queue": log_queue,
|
||||
"loop": loop,
|
||||
@@ -368,4 +387,3 @@ class DouyuBatchRegistry:
|
||||
|
||||
|
||||
douyu_batch_registry = DouyuBatchRegistry()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user