feat(monitor): 超级编导自动追加,任务设置里按间隔补新作品
Deploy VitePress site to Pages / build (push) Canceled after 0s
Deploy VitePress site to Pages / Deploy (push) Canceled after 0s

任务编辑里新增「自动从超级编导追加新作品」(抖音 + 作品模式才有):

- 每 N 分钟(默认 2 小时)按**发布时间**查一次数据中心,把这段时间新发布、
  还没在任务里的作品追加进去;已有的不会重复。
- start_time/end_time 实测按发布时间过滤,所以老活动里今天才发的作品也能
  收到 —— 按活动创建时间筛会整批漏掉。
- 查询窗口首尾重叠 1 小时,兜住数据中心的索引延迟;失败时 last_at 不动,
  恢复后这段时间的作品仍在窗口里,只把调度钟按 30 分钟退避重试。
- 同步跑在后台任务里,不阻塞采集调度。

Co-Authored-By: Claude <[email protected]>
This commit is contained in:
2026-10-25 07:58:05 +08:00
co-authored by Claude
parent 809692a957
commit be22b30a83
8 changed files with 470 additions and 4 deletions
+33
View File
@@ -245,6 +245,12 @@ async def create_task(session: AsyncSession, payload: Dict[str, Any]) -> Monitor
platform = payload.get("platform") or PLATFORM_XHS
platforms.ensure_runnable(platform)
# 超级编导只接抖音分发,追加进去的又只能是作品 id —— 别的组合开了也永远不会跑,
# 与其让它静静地什么都不做,不如在保存时就说清楚。
superdir_auto = bool(payload.get("superdir_auto_enabled", False))
if superdir_auto and (platform != adapters.PLATFORM_DY or mode != MODE_NOTE):
raise ValueError("超级编导自动追加只能用在抖音的作品模式任务上")
now = get_current_timestamp()
# Fall back to the configured defaults for anything the caller left out, so
@@ -274,6 +280,11 @@ async def create_task(session: AsyncSession, payload: Dict[str, Any]) -> Monitor
run_timeout_seconds=payload.get("run_timeout_seconds", 3600),
notify_enabled=payload.get("notify_enabled", False),
notify_failures=payload.get("notify_failures", True),
# 超级编导自动追加。刚打开时下一轮 tick 就会跑一次(窗口从一个间隔前算),
# 不需要等到「创建后两小时」。
superdir_auto_enabled=bool(payload.get("superdir_auto_enabled", False)),
superdir_auto_interval_minutes=payload.get("superdir_auto_interval_minutes") or 120,
superdir_auto_next_at=now if payload.get("superdir_auto_enabled") else None,
next_run_at=schedule.next_occurrence(
mode=schedule_mode,
interval_minutes=interval_minutes,
@@ -332,10 +343,26 @@ async def update_task(session: AsyncSession, task_id: int, payload: Dict[str, An
"run_timeout_seconds",
"notify_enabled",
"notify_failures",
"superdir_auto_interval_minutes",
):
if field in payload and payload[field] is not None:
setattr(task, field, payload[field])
# 自动追加的开关要顺带经营调度钟:刚打开就排一次(否则新开的人要等一整个间隔
# 才看到第一次同步);关掉就清掉,免得停了几个月之后又被 tick 捡起来。
if payload.get("superdir_auto_enabled") is not None:
auto_enabled = bool(payload["superdir_auto_enabled"])
if auto_enabled and (
task.platform != adapters.PLATFORM_DY or task.mode != MODE_NOTE
):
raise ValueError("超级编导自动追加只能用在抖音的作品模式任务上")
if auto_enabled and not task.superdir_auto_enabled:
task.superdir_auto_next_at = get_current_timestamp()
task.superdir_auto_last_error = ""
task.superdir_auto_enabled = auto_enabled
if not auto_enabled:
task.superdir_auto_next_at = None
# The clock lists are stored as comma-separated text, so they cannot go
# through the generic loop above.
if payload.get("schedule_hours") is not None:
@@ -1343,6 +1370,12 @@ async def list_tasks(
"run_timeout_seconds": task.run_timeout_seconds,
"notify_enabled": task.notify_enabled,
"notify_failures": task.notify_failures,
"superdir_auto_enabled": task.superdir_auto_enabled,
"superdir_auto_interval_minutes": task.superdir_auto_interval_minutes,
"superdir_auto_next_at": task.superdir_auto_next_at,
"superdir_auto_last_at": task.superdir_auto_last_at,
"superdir_auto_last_added": task.superdir_auto_last_added,
"superdir_auto_last_error": task.superdir_auto_last_error,
"next_run_at": task.next_run_at,
"last_run_at": task.last_run_at,
"last_status": task.last_status,