fix(monitor): 卡死的一轮不再堵住调度循环;矩阵补总获赞和首条视频日期
「抓不到最新的」有两个叠加的原因: 1. 采集卡死时 `_run_due_task` 是内联 await,execute_task 里的 wait_for 又在等 一个不响应取消的协程 —— 整个调度循环(连同自动追加、每日推送、其他任务) 一起停 65 分钟。现在采集丢到后台任务里跑,循环照常 tick,reap_stale_runs 也能按时回收。实测任务 25 最近 8 次运行有 4 次这样。 2. 超级编导自动追加在 10-25 因密码错误被停到 11-24(防锁号),新作品进不来。 已把 25 号的调度钟拨回现在,补进了 10-31 那条。 标签矩阵:博主名字左边在粉丝数之后加「主页总获赞」和「第一条视频发布日期」 (查全库最早的作品时间,不受 7/14/30 天窗口限制)。
This commit is contained in:
@@ -262,6 +262,7 @@ async def _stat(
|
||||
captured_at: int | None = None,
|
||||
run_id: int = 1,
|
||||
fans: int | None = None,
|
||||
total_favorited: int | None = None,
|
||||
) -> None:
|
||||
async with monitor_db.get_session() as session:
|
||||
session.add(
|
||||
@@ -273,6 +274,7 @@ async def _stat(
|
||||
creator_id="",
|
||||
works_count=0,
|
||||
fans=fans,
|
||||
total_favorited=total_favorited,
|
||||
captured_at=captured_at or get_current_timestamp(),
|
||||
)
|
||||
)
|
||||
@@ -317,6 +319,52 @@ async def test_the_creator_row_carries_the_latest_fan_count(db):
|
||||
assert data["creators"][0]["fans"] == 1200
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_the_creator_row_carries_the_total_likes_from_the_profile(db):
|
||||
"""名字左边还要显示主页上的「获赞总数」,同样取最近一次读到的值。"""
|
||||
task_id = await _task()
|
||||
now = get_current_timestamp()
|
||||
await _stat(
|
||||
task_id, "hash-a", "博主A",
|
||||
captured_at=now - 60_000, total_favorited=80000, run_id=1,
|
||||
)
|
||||
await _stat(
|
||||
task_id, "hash-a", "博主A",
|
||||
captured_at=now, total_favorited=83000, run_id=2,
|
||||
)
|
||||
|
||||
async with monitor_db.get_session() as session:
|
||||
data = await service.daily_tag_matrix(session, "dy", days=7)
|
||||
|
||||
assert data["creators"][0]["total_favorited"] == 83000
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_the_first_video_date_comes_from_the_whole_table(db):
|
||||
"""第一条视频可能远在日期窗口之外 —— 要查全库,不能只看这 7 天。"""
|
||||
task_id = await _task()
|
||||
now = get_current_timestamp() - 1000
|
||||
first = now - 400 * DAY_MS
|
||||
await _note(task_id, "old", "博主A", first)
|
||||
await _note(task_id, "new", "博主A", now)
|
||||
|
||||
async with monitor_db.get_session() as session:
|
||||
data = await service.daily_tag_matrix(session, "dy", days=7)
|
||||
|
||||
assert data["creators"][0]["first_published_at"] == first
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_a_creator_without_works_has_no_first_video_date(db):
|
||||
task_id = await _task()
|
||||
await _stat(task_id, "hash-a", "博主A", fans=10)
|
||||
|
||||
async with monitor_db.get_session() as session:
|
||||
data = await service.daily_tag_matrix(session, "dy", days=7)
|
||||
|
||||
assert data["creators"][0]["first_published_at"] is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_a_creator_without_a_snapshot_has_no_fan_count(db):
|
||||
"""作品模式刚导入、还没跑过一轮:粉丝数留 None,界面不画那个数字(不是 0)。"""
|
||||
|
||||
Reference in New Issue
Block a user