feat: home growth auto(7→1) and hourly recent-video snapshot

- Add analytics.home_growth_days (auto|1|7); API growth_days=auto tries 7 then 1
- Homepage shows active window and growth-board link; clearer empty reason
- New snapshot_recent scheduler task (schedule.recent_snapshot_minutes/days)
- run_recent_videos refreshes new aids only; never touches completed/backup
- Full 00:01 job keeps ok=1 skip (covers hourly refresh within 1h); mutex with recent
This commit is contained in:
bot-ci committed 2026-11-02 10:00:02 +08:00
1 parent 04716aec1b
commit 9163f47b76
15 files changed
+496 -22

No files matched your search

+96 -1
View File
@@ -4,7 +4,8 @@
规则(DEVELOPMENT.md §7.4):
* 对 ``active`` / ``unfaved`` 视频逐条请求 ``view``;
* 成功写入七项指标;``ok=1`` 的同日快照直接跳过(断点续跑);
* 成功写入七项指标;``ok=1`` 的同日快照直接跳过(断点续跑;含小时任务 1 小时内刚刷新的);
* ``run_recent_videos`` 只刷新近 N 天新片的当日行,不改完成日 / 备份;
* 视频不可访问时标记 ``removed``;
* 其他错误最多重试 3 次,仍失败写 ``ok=0`` 占位,不写假零值;
* 对 ``track_fans`` 逐个请求 ``relation/stat``(独立任务,不影响视频完成日);
@@ -198,6 +199,8 @@ class SnapshotService:
for index, aid in enumerate(videos, 1):
existing = self.repo.get_snapshot(stat_date, aid)
if existing is not None and int(existing.get("ok") or 0) == 1 and not force:
# 断点续跑:同日已成功则跳过。小时任务刷新过的行也是 ok=1,
# 自然覆盖「1 小时内 captured_at 已更新则不再次更新」的要求。
summary.skipped += 1
continue
@@ -269,6 +272,98 @@ class SnapshotService:
)
return summary
def run_recent_videos(
self,
*,
date: str | None = None,
recent_days: int | None = None,
) -> SnapshotSummary:
"""刷新近 N 天新视频的当日快照;不碰完成日标记与日备份。
「近 N 天」按 pubdate 墙钟窗口:``now - recent_video_days * 86400``,
不是上海日历日差。允许覆盖同日已有 ``ok=1`` 行以便小时级刷新。
"""
cfg = self.config_store.get()
client = self._client()
now = self._now()
stat_date = date or shanghai_date(now)
if not is_date(stat_date):
raise ValueError(f"日期格式必须是 YYYY-MM-DD: {stat_date!r}")
days = (
int(cfg.schedule.recent_video_days)
if recent_days is None else int(recent_days)
)
if days < 1:
raise ValueError("recent_days 必须 >= 1")
# 墙钟窗口,而非按上海日历截断到日界。
since_pubdate = now - days * 86400
summary = SnapshotSummary(stat_date=stat_date, started_at=now)
self._log(
"info", "snapshot.recent_start",
stat_date=stat_date, recent_days=days, since_pubdate=since_pubdate,
)
videos = self.repo.video_aids_recent_for_snapshot(since_pubdate=since_pubdate)
summary.total = len(videos)
for index, aid in enumerate(videos, 1):
stat, error, unavailable = self._fetch_view(client, aid)
if unavailable:
summary.removed += 1
self.repo.set_video_status(aid, "removed", now=now)
self._log(
"warning", "snapshot.recent_removed",
stat_date=stat_date, aid=aid, error=error,
)
elif stat is not None:
self.repo.upsert_snapshot(
stat_date,
aid,
metrics=stat.metrics(),
ok=True,
err=None,
captured_at=self._now(),
)
if getattr(stat, "up_face", None):
self.repo.apply_video_up_face(aid, stat.up_face)
summary.success += 1
else:
summary.failed += 1
self.repo.upsert_snapshot(
stat_date,
aid,
metrics=None,
ok=False,
err=error,
captured_at=self._now(),
)
summary.errors.append(f"aid {aid}: {error}")
self._log(
"error", "snapshot.recent_failed",
stat_date=stat_date, aid=aid, error=error,
)
if self.progress_every > 0 and (
index % self.progress_every == 0 or index == summary.total
):
self._log(
"info", "snapshot.recent_progress",
stat_date=stat_date, done=index, total=summary.total,
success=summary.success, failed=summary.failed,
removed=summary.removed,
)
# 刻意不写 snapshot:completed / last_completed / 日备份:完成日只归全量任务。
summary.completed = summary.failed == 0
if summary.success or summary.removed or summary.failed:
self.repo.bump_cache_version("videos")
summary.finished_at = self._now()
self._log(
"info" if summary.completed else "warning",
"snapshot.recent_done",
**summary.as_dict(),
)
return summary
def run_fans_if_needed(
self, *, date: str | None = None, force: bool = False
) -> SnapshotSummary: