diff --git a/README.md b/README.md index 1737ff5..671a819 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ 基于 **uiautomator2 + Flask + 自建设备池** 的 Android 多设备自动化任务执行平台(已摘除 OpenSTF 依赖)。 -提供 Web 管理后台,支持多设备并发任务执行、定时调度、设备分组管理、设备池管理(新增/停用/删除/型号采集)、APK 批量安装、网页远程看屏(MJPEG 实时流 + 触控)、UI 元素抓取等功能。内置抖音养号任务和通用步骤任务,可扩展任意 App 的自动化操作。 +提供 Web 管理后台,支持多设备并发任务执行、定时调度、设备分组管理、设备池管理(新增/停用/删除/型号采集)、APK 批量安装、网页远程看屏(MJPEG 实时流 + 触控)、UI 元素抓取等功能。内置通用步骤任务(可视化步骤编辑器编排,覆盖任意 App 的操作),可扩展专属任务类型。 --- @@ -105,8 +105,7 @@ platform-tools/ ├── tasks/ # 任务定义层(每个 App 一个子包) │ ├── __init__.py # 全局任务注册表 │ ├── base.py # BaseTask 基类 + @register_task 装饰器 -│ ├── douyin/ # 抖音养号任务 -│ └── generic/ # 通用步骤任务(可视化编辑器编排) +│ └── generic/ # 通用步骤任务(可视化编辑器编排,当前唯一任务类型) │ └── task.py # 步骤执行引擎(open_app/click/swipe/if_el...) │ ├── templates/admin/ # 前端页面 @@ -183,8 +182,7 @@ Worker.run_task(执行业务逻辑) | 任务类型 | task_type | 说明 | |---------|-----------|------| -| 抖音养号 | `douyin_nurture` | 自动看视频 + 随机点赞,被退出自动重连 | -| 通用步骤 | `generic_steps` | 可视化步骤编辑器编排流程,支持循环/点击/滑动等 | +| 通用步骤 | `generic_steps` | 可视化步骤编辑器编排流程,支持循环/点击/滑动/条件/OCR 等 | ### TaskJob — 任务计划 @@ -192,9 +190,9 @@ Worker.run_task(执行业务逻辑) | 字段 | 说明 | 示例 | |------|------|------| -| `task_type` | 任务类型 | `"douyin_nurture"` | +| `task_type` | 任务类型 | `"generic_steps"` | | `target` | 目标设备 | `{"mode": "all"}` 或 `{"mode": "group", "group_name": "A组"}` 或 `{"mode": "serial", "serial": "192.168.1.100:5555"}` | -| `params` | 任务参数(与默认值深合并) | `{"watch_count": 50, "actions": {"like": {"params": {"rate": 0.5}}}}` | +| `params` | 任务参数(与默认值深合并) | `{"max_duration": 0, "steps": [{"type": "open_app", "params": {"package": "com.ss.android.ugc.aweme"}}]}` | | `schedule` | 调度策略 | `{"mode": "once"}` 或 `{"mode": "cron", "cron": "0 9 * * *"}` 或 `{"mode": "cron_stop", "cron": "0 9 * * *", "stop_cron": "0 18 * * *"}` | | `retry` | 重试策略 | `{"max_attempts": 3, "delay": 60}` | | `enabled` | 是否启用 | `true` | @@ -306,23 +304,6 @@ self.set_progress(done=5, total=80, unit="视频", ## 任务系统 -### 抖音养号(douyin_nurture) - -自动观看抖音视频,按配置随机执行点赞操作。参数(在 `tasks/douyin/task.py` 顶部): - -| 参数 | 默认值 | 说明 | -|------|--------|------| -| `watch_count` | 80 | 观看视频数量(0=不限,靠时长停止) | -| `watch_min` / `watch_max` | 5.0 / 35.0 | 单视频观看时长范围(秒) | -| `max_duration` | 0 | 最大运行时长(秒),0=不限时 | -| `swipe_min` / `swipe_max` | 0.25 / 0.50 | 上滑手势时长范围(秒) | -| `gap_min` / `gap_max` | 1.0 / 3.0 | 视频间隔时长范围(秒) | -| `actions.like.enabled` | true | 是否启用点赞 | -| `actions.like.params.rate` | 0.3 | 点赞概率(0~1) | -| `actions.like.params.method` | by_element | 点赞方式:by_element(找红心) / double_click(双击) | - -终止条件(哪个先到就停):`watch_count` 数量到 / `max_duration` 时长到 / 手动停止。 - ### 通用步骤(generic_steps) 通过可视化步骤编辑器编排任务流程,worker 按步骤顺序执行。支持的步骤类型: @@ -352,7 +333,8 @@ self.set_progress(done=5, total=80, unit="视频", ### 新增 App 任务 -参照 `tasks/douyin/` 结构,6 步即可新增一个 App 任务,详见 [doc/TASK_DEV.md](doc/TASK_DEV.md)。 +参照 `tasks/generic/` 结构,即可新增一个专属任务类型,详见 [doc/TASK_DEV.md](doc/TASK_DEV.md)。 +(注:当前平台只保留 `generic_steps` 一种类型;绝大多数 App 操作直接用步骤编辑器编排即可,不必新建类型。) --- @@ -371,7 +353,7 @@ self.set_progress(done=5, total=80, unit="视频", ```python from core.logger import get_logger -log = get_logger("task.douyin") # 写入 task.log +log = get_logger("task.generic") # 写入 task.log log.info(f"[{self.serial}] 开始任务") ``` diff --git a/core/__init__.py b/core/__init__.py index 986affd..3a40263 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -1,7 +1,7 @@ """core 包:基础设施层。 - config — 全局配置常量(STF、adb 路径、养号参数) + config — 全局配置常量(adb 路径、设备发现等) adb_helper — adb 命令封装(并发安全) - device_worker — 设备生命周期 + 养号 worker + 全局状态注册表 + device_worker — 设备生命周期 + 任务 worker 基类 + 全局状态注册表 task_manager — 任务管理框架(分组/计划/调度/重试/持久化) """ diff --git a/core/actions/__init__.py b/core/actions/__init__.py index d19eeff..d28a013 100644 --- a/core/actions/__init__.py +++ b/core/actions/__init__.py @@ -1,7 +1,7 @@ """全局操作框架:所有 app 任务共用的 Action 基类与注册机制。 为什么放这里: - 抖音的点赞/评论 xpath 只适用抖音,留在 tasks/douyin/actions/。 + 某个 app 专属的 xpath 只适用那个 app,留在 tasks//actions/。 但"操作"的抽象(BaseAction 接口、概率触发、注册机制)是通用的, 放这里让所有 app 任务共享同一套操作开发范式。 diff --git a/core/actions/base.py b/core/actions/base.py index fb1e83c..4924675 100644 --- a/core/actions/base.py +++ b/core/actions/base.py @@ -3,11 +3,11 @@ 设计要点: 1. BaseAction 定义统一接口:execute(d, params, worker) -> bool 2. 每个 app 任务有自己的注册表(create_action_registry), - 互不污染——抖音的 like 和快手的 like 各注册各的。 + 互不污染——A 应用的 like 和 B 应用的 like 各注册各的。 3. 概率触发、状态上报等通用逻辑放这里,子类不重复写。 4. ActionContext 封装执行上下文,方便扩展(传 d/worker/进度/计数器)。 -新增 app 专属操作步骤(照着 tasks/douyin/actions/like.py 抄): +新增 app 专属操作步骤(在 tasks//actions/ 下新建,参考该包已有实现): 1. 在 tasks//actions/ 下新建 my_action.py 2. 写一个 BaseAction 子类,用 @register_action 装饰,实现 execute: diff --git a/core/logger.py b/core/logger.py index ab2b440..bc37006 100644 --- a/core/logger.py +++ b/core/logger.py @@ -41,7 +41,7 @@ def get_logger(name="core"): """获取指定模块的 logger。 name: 模块名(core/task/web/action),决定写哪个文件。 - 也可传子模块名如 "task.douyin",会归到 task.log。 + 也可传子模块名如 "task.generic",会归到 task.log。 返回配置好的 logging.Logger。 """ if name in _LOGGERS: diff --git a/core/models.py b/core/models.py index cff3af0..d4a32f2 100644 --- a/core/models.py +++ b/core/models.py @@ -128,7 +128,7 @@ class TaskJob(db.Model): """ id = db.Column(db.String(32), primary_key=True) # uuid 前 8 位 name = db.Column(db.String(120), nullable=False) - task_type = db.Column(db.String(60), default="douyin_nurture") + task_type = db.Column(db.String(60), default="generic_steps") target = db.Column(db.Text, default='{"mode":"all"}') # JSON params = db.Column(db.Text, default="{}") # JSON schedule = db.Column(db.Text, default='{"mode":"once"}') # JSON @@ -384,7 +384,7 @@ def _migrate_old_json(): del actions["comment"] _log.info(f"迁移任务 {j.get('name')}: 已剔除废弃的 comment 配置") row = TaskJob(id=j["id"], name=j["name"], - task_type=j.get("task_type", "douyin_nurture"), + task_type=j.get("task_type", "generic_steps"), enabled=j.get("enabled", True)) row.set_target(j.get("target", {"mode": "all"})) row.set_params(params) diff --git a/core/task_manager.py b/core/task_manager.py index 21f8660..1f97b0e 100644 --- a/core/task_manager.py +++ b/core/task_manager.py @@ -1,9 +1,9 @@ """通用任务管理框架:任务类型注册 + 设备分组 + 任务计划 + 定时调度 + 重试 + 持久化。 -设计目标:可扩展,未来加非抖音任务只需注册新的 Task 类。 +设计目标:可扩展——新增任务类型只需在 tasks/ 下注册新的 Task 类(见 doc/TASK_DEV.md)。 核心概念: - TaskType — 任务类型(如"抖音养号"),可注册,含默认参数和 worker 工厂 + TaskType — 任务类型(如"通用步骤"),可注册,含默认参数和 worker 工厂 DeviceGroup — 设备分组,持久化到 SQLite(core.models.DeviceGroup) TaskJob — 任务计划(类型+目标+参数+调度+重试),持久化到 SQLite(core.models.TaskJob) TaskManager — 统管调度器、分组、任务、运行实例、状态 @@ -121,7 +121,7 @@ class DeviceGroup: class TaskJob: """一个任务计划:什么任务、跑哪些设备、什么参数、何时跑、失败重试策略。""" - def __init__(self, job_id=None, name="", task_type="douyin_nurture", + def __init__(self, job_id=None, name="", task_type="generic_steps", target=None, params=None, schedule=None, retry=None, enabled=True): self.id = job_id or uuid.uuid4().hex[:8] self.name = name @@ -378,24 +378,22 @@ class TaskManager: for row in GroupRow.query.all(): g = DeviceGroup(row.name, row.get_serials(), row.description or "") self.groups[g.name] = g - dirty = False # 标记是否有任务参数需要写回 + stale = [] # 任务类型已不存在(历史任务类型被删除)的任务 for row in JobRow.query.all(): j = TaskJob(job_id=row.id, name=row.name, task_type=row.task_type, target=row.get_target(), params=row.get_params(), schedule=row.get_schedule(), retry=row.get_retry(), enabled=row.enabled) - # 数据规整:移除已废弃的 action 配置(如抖音的 comment 已删除) - if j.task_type == "douyin_nurture": - actions = j.params.get("actions", {}) - if "comment" in actions: - del actions["comment"] - row.set_params(j.params) - dirty = True - _log.info(f"任务 {j.name}({j.id}): 已移除废弃的 comment 配置") + # 启动时告警:库里留着已删除的任务类型(如 douyin_nurture), + # 这类任务跑不起来也不该静默——提示人工删除或改用现有类型。 + # 只告警不改数据(不自动删用户的任务)。 + if not get_task_class(j.task_type): + stale.append(j) self.jobs[j.id] = j - if dirty: - db.session.commit() - _log.info("已将规整后的任务参数写回数据库") + if stale: + _log.warning( + "以下任务的任务类型已不存在,无法执行,请在「任务」页删除或改用现有类型:" + + ";".join(f"{j.name}({j.id}, type={j.task_type})" for j in stale)) _log.info(f"从数据库加载 {len(self.groups)} 个分组, {len(self.jobs)} 个任务") except Exception as e: _log.error(f"从数据库加载失败: {e}") @@ -608,6 +606,11 @@ class TaskManager: job = self.jobs.get(job_id) if not job: return {"ok": False, "error": "任务不存在"} + # 任务类型已不存在(历史类型被删除)→ 明确报错,别只返回"已触发"然后线程里静默失败 + if not get_task_class(job.task_type): + return {"ok": False, "error": + f"任务类型 {job.task_type} 已不存在(该类型已被删除)," + f"请删除此任务或改用现有类型"} # 在独立线程跑,不阻塞调用方 t = threading.Thread(target=self._run_job, args=(job,), daemon=True) t.start() diff --git a/doc/AI_TASK_GEN.md b/doc/AI_TASK_GEN.md index 178e107..c376b70 100644 --- a/doc/AI_TASK_GEN.md +++ b/doc/AI_TASK_GEN.md @@ -23,7 +23,8 @@ - **入口**:AI 控制台加「聊天 / AI 建任务」模式开关,复用会话/SSE/设备选择/停止/刷新恢复骨架。不新建顶级 Tab。 - **产出方式**:**AI 直接撰写编辑器的步骤 JSON**(非操作轨迹翻译)。自探信息只作上下文与审计;探索中的误点/多余截图不会混入任务。 -- **任务类型**:P0 **只产 `generic_steps`**(通用步骤)。`douyin_nurture` 预设参数生成放 P1。 +- **任务类型**:**只产 `generic_steps`**(通用步骤)——平台当前唯一的任务类型 + (原 `douyin_nurture` 预设参数生成已随该类型删除,不再做)。 - **定位原则:全部基于 UI 树**: - 模型定位/点击一律走 `de_ui_tree` 拿到的元素(`text`/`id`/`description`/`text_contains`),多实例用 index,或后端 `uiauto_helper` 生成的 `//*[@resource-id=..][k]` XPath; - `de_tap_element` 确认能命中后才写进 `click` 步骤; @@ -134,8 +135,8 @@ - 尽量不写死坐标;P0 默认禁 `click_xy`,产物以树元素定位为主。 ## 6. 里程碑 -- **P0(本设计主体)**:designer 模式 → 自探(UI 树定位)→ 直接撰写 generic_steps draft → 服务端 schema 校验 → 前端步骤编辑器预填确认保存。验收:一句话在真实设备上生成一条可调度的 generic_steps,步骤全部来自 UI 树且编辑器可打开。 -- **P1**:`douyin_nurture` 参数预设生成(照 default_params 结构);模板沉淀:把 draft+需求写入 `agent_experience`(新列存结构化 steps 或 JSON),相似需求注入参考;整链「演示试跑」(把 steps 在设备上以受控方式跑一遍并截图回报,需新增端点,复刻 `device_busy` 拒绝语义)。 +- **P0(本设计主体)**:designer 模式 → 自探(UI 树定位)→ 直接撰写 generic_steps draft → 服务端 schema 校验 → 前端步骤编辑器预填确认保存。验收:一句话在真实设备上生成一条可调度的 generic_steps,步骤全部来自 UI 树且编辑器可打开。(平台只剩 generic_steps 一种任务类型,与原规划一致) +- **P1**:模板沉淀:把 draft+需求写入 `agent_experience`(新列存结构化 steps 或 JSON),相似需求注入参考;整链「演示试跑」(把 steps 在设备上以受控方式跑一遍并截图回报,需新增端点,复刻 `device_busy` 拒绝语义)。 - **进展(2026-09-10)**:动作级沉淀已落地——`agent_action` 表 + 从**成功步骤**蒸馏"命名动作"(steps 用编辑器 schema、带元素定位、禁坐标)+ 执行前按名/别名召回注入(`web/agent_api.py`)。AI 建任务可直接把这些动作当作 generic_steps 的**预制件**复用。 - **P2**:自定义动作支持(内联展开成 group,或新增 `action_ref` 节点 + 执行器/编辑器同步);多设备并行;成本与 token 控制。 diff --git a/doc/API.md b/doc/API.md index ad3fd4f..b38fb0e 100644 --- a/doc/API.md +++ b/doc/API.md @@ -141,7 +141,7 @@ "counts": {"total": 8, "running": 1, "done": 5, "error": 1, "failed": 1, "idle": 0}, "errors": [ {"serial": "192.168.1.100:5555", "model": "Pixel 6", "status": "failed", - "last_error": "重试3次失败", "task": "抖音养号", "attempt": 3, "updated": 1700000000.0} + "last_error": "重试3次失败", "task": "刷视频-上午", "attempt": 3, "updated": 1700000000.0} ] } ``` @@ -218,12 +218,6 @@ { "ok": true, "task_types": [ - { - "task_type": "douyin_nurture", - "name": "抖音养号", - "description": "自动观看抖音视频...", - "default_params": {"watch_count": 80, "...": "..."} - }, { "task_type": "generic_steps", "name": "通用步骤", @@ -265,7 +259,7 @@ ```json { "ok": true, - "jobs": [{"id": "abc123", "name": "抖音养号", "task_type": "douyin_nurture", + "jobs": [{"id": "abc123", "name": "刷视频-上午", "task_type": "generic_steps", "next_run": "2026-08-12 09:00", "coverage": {"mode": "all", "total": 3, "serials": ["192.168.20.206:5555", "..."]}, @@ -296,10 +290,10 @@ **请求**(JSON): ```json { - "name": "抖音养号", - "task_type": "douyin_nurture", + "name": "刷视频-上午", + "task_type": "generic_steps", "target": {"mode": "all"}, - "params": {"watch_count": 50, "actions": {"like": {"params": {"rate": 0.5}}}}, + "params": {"max_duration": 0, "steps": [{"type": "open_app", "params": {"package": "com.ss.android.ugc.aweme"}}]}, "schedule": {"mode": "cron", "cron": "0 */2 * * *"}, "retry": {"max_attempts": 3, "delay": 60}, "enabled": true @@ -327,7 +321,7 @@ **请求**(JSON): ```json -{"params": {"watch_count": 100}} +{"params": {"max_duration": 1800}} ``` **响应**: @@ -354,7 +348,7 @@ **响应**: ```json -{"ok": true, "msg": "任务 抖音养号 已触发"} +{"ok": true, "msg": "任务 刷视频-上午 已触发"} ``` ### POST /api/jobs//toggle diff --git a/doc/ARCHITECTURE.md b/doc/ARCHITECTURE.md index 42a8c3d..224790b 100644 --- a/doc/ARCHITECTURE.md +++ b/doc/ARCHITECTURE.md @@ -275,8 +275,7 @@ APK 上传/解析/批量安装。 ``` tasks/__init__.py ├── from .base import BaseTask, register_task, list_task_types, get_task_class - ├── from .douyin import task # 触发 @register_task - └── from .generic import task # 触发 @register_task + └── from .generic import task # 触发 @register_task(当前唯一任务类型) ``` `@register_task` 装饰器将 Task 类注册到全局 `_TASK_TYPES` 字典,key 为 `task_type` 字符串。 @@ -301,9 +300,12 @@ Job 下发时只传需要覆盖的字段,调度器做三层合并: 每个 App 有独立的 Action 注册表(`create_action_registry()`),互不污染。 ``` -core/actions/base.py — BaseAction 全局基类 + should_trigger + register_action -tasks/douyin/actions/base.py — ACTIONS = create_action_registry() + list/get 函数 -tasks/douyin/actions/like.py — @register_action(ACTIONS) LikeAction +core/actions/base.py — BaseAction 全局基类 + should_trigger + register_action +tasks//actions/base.py — ACTIONS = create_action_registry() + list/get 函数 +tasks//actions/xxx.py — @register_action(ACTIONS) XxxAction + +> 当前没有 App 专属任务包(只剩 `tasks/generic/`,步骤全走通用 STEP_TYPES,不建专属 action 表); +> 新增专属任务类型时按上面三行建 `tasks//actions/`。 ``` **循环导入坑**:`actions/__init__.py` 必须先 `from .base import ACTIONS`,再 `from . import like`。 diff --git a/doc/DEVELOPMENT.md b/doc/DEVELOPMENT.md index 2a7d29e..fcd053d 100644 --- a/doc/DEVELOPMENT.md +++ b/doc/DEVELOPMENT.md @@ -176,9 +176,11 @@ with sync_playwright() as p: ## 5. 常见开发任务 -### 5.1 新增 App 任务 +### 5.1 新增 App 任务类型 -参照 `tasks/douyin/` 结构,详见 **[doc/TASK_DEV.md](TASK_DEV.md)**(6 步模板)。 +参照 `tasks/generic/` 结构,详见 **[doc/TASK_DEV.md](TASK_DEV.md)**(6 步模板)。 +注意:当前平台**只保留 `generic_steps` 一种任务类型**;大多数 App 操作直接用步骤编辑器 +编排即可,不必新增任务类型。 ``` tasks// diff --git a/doc/TASK_DEV.md b/doc/TASK_DEV.md index 0749dff..d709102 100644 --- a/doc/TASK_DEV.md +++ b/doc/TASK_DEV.md @@ -62,18 +62,13 @@ platform-tools/ │ ├── __init__.py # create_action_registry / register_action / should_trigger │ └── base.py # BaseAction 全局基类 ├── tasks/ # 任务定义层 -│ ├── __init__.py # 聚合导出 + import 各任务包触发注册(from .douyin/.generic import task) +│ ├── __init__.py # 聚合导出 + import 各任务包触发注册(from .generic import task) │ ├── base.py # BaseTask 基类 + _TASK_TYPES + register_task/list_task_types/get_task_class -│ ├── douyin/ # 抖音养号(task_type=douyin_nurture,示例) -│ │ ├── __init__.py -│ │ ├── task.py # DEFAULT_PARAMS + Worker + Task + @register_task -│ │ └── actions/ -│ │ ├── __init__.py # 先 from .base import ACTIONS,再 from . import like -│ │ ├── base.py # ACTIONS = create_action_registry() -│ │ └── like.py # @register_action(ACTIONS) LikeAction -│ └── generic/ # 通用步骤任务(task_type=generic_steps,步骤编辑器编排) +│ └── generic/ # 通用步骤任务(task_type=generic_steps,当前唯一任务类型) │ ├── __init__.py │ └── task.py # STEP_TYPES + Worker + Task(按 steps 顺序执行)+ test_step +│ +│ # 新增专属任务类型时:按同样结构建 /(见 §6「新增任务类型」的骨架) ├── templates/admin/ │ ├── monitor.html # 单页应用(7 Tab + 页内子分栏,纯前端渲染) │ ├── login.html # 登录页 @@ -130,9 +125,9 @@ platform-tools/ ### 2.1 TaskType — 任务类型 -一个 `TaskType` 描述"做什么"(例如抖音养号、通用步骤),由 `Task` 子类 + `Worker` 子类 + `DEFAULT_PARAMS` 组成。每个 `TaskType` 注册到全局 `_TASK_TYPES` 字典,key 为任务类型字符串,value 为 `Task` 类。 +一个 `TaskType` 描述"做什么"(例如通用步骤、某个 App 的专属养号流程),由 `Task` 子类 + `Worker` 子类 + `DEFAULT_PARAMS` 组成。每个 `TaskType` 注册到全局 `_TASK_TYPES` 字典,key 为任务类型字符串,value 为 `Task` 类。 -> **注册位置**:`_TASK_TYPES` 及 `register_task` / `list_task_types` / `get_task_class` **定义在 `tasks/base.py`**;`tasks/__init__.py` 只做两件事——`from .base import ...` 聚合导出,以及 `from .douyin/.generic import task` 触发各任务包注册。**当前已注册的 task_type 仅 `douyin_nurture` 与 `generic_steps`**,前端"新建任务"下拉来自 `GET /api/task_types`。新增 task_type 需在 `tasks/` 下建子包、用 `@register_task` 装饰,并在 `tasks/__init__.py` 加 `from .xxx import task`,然后**重启 web** 生效。 +> **注册位置**:`_TASK_TYPES` 及 `register_task` / `list_task_types` / `get_task_class` **定义在 `tasks/base.py`**;`tasks/__init__.py` 只做两件事——`from .base import ...` 聚合导出,以及 `from .generic import task` 触发各任务包注册。**当前已注册的 task_type 只有 `generic_steps`(通用步骤)**,前端"新建任务"下拉来自 `GET /api/task_types`。新增 task_type 需在 `tasks/` 下建子包、用 `@register_task` 装饰,并在 `tasks/__init__.py` 加 `from .xxx import task`,然后**重启 web** 生效。 ```python # tasks/base.py @@ -151,7 +146,7 @@ def get_task_class(task_type): `TaskJob` 是"什么时候、在哪些设备上、用什么参数执行某个 TaskType"的持久化计划,存于 SQLite(`data/users.db` 的 `task_job` 表)。包含字段: -- `task_type` — 任务类型(对应 `_TASK_TYPES` 的 key;当前仅 `douyin_nurture` / `generic_steps`) +- `task_type` — 任务类型(对应 `_TASK_TYPES` 的 key;当前仅 `generic_steps`,新建任务不传时默认就是它) - `target` — 目标设备:`{"mode": "all"|"group"|"serial", "group_name": "", "serial": ""}`,默认 `{"mode":"all"}` - `params` — 任务参数(与 `DEFAULT_PARAMS` 深合并)。含两个隐藏开关: - `skip_offline`(默认 **true**)— serial/group 模式先跳过本机 adb 不可达(离线)的设备 @@ -198,11 +193,11 @@ Worker 通过 `self.set_progress(**fields)` 上报进度,前端统一解析展 **示例**: ```python -# 抖音任务(有数量限制) +# 有数量限制的任务 self.set_progress(done=5, total=80, unit="视频", action_counts={"like": 3}, elapsed=120) -# 抖音任务(仅时长限制,无数量) +# 仅时长限制(无数量)的任务 self.set_progress(done=5, total=0, unit="视频", action_counts={"like": 3}, elapsed=120) @@ -346,7 +341,7 @@ adb + u2 **只读连接**试执行单步并验证选择器,返回 `result` = * > **签名提醒**:以下模板的 `Worker.__init__` / `Task.create_worker` **已去掉 `stf_client` / `stf` > 参数**——现行签名是 `BaseWorker.__init__(self, serial, params=None, daemon=True)`、 -> `Task.create_worker(self, serial, params)`(对照 `tasks/douyin/task.py`),新增任务照此抄, +> `Task.create_worker(self, serial, params)`(对照 `tasks/generic/task.py`),新增任务照此抄, > 不要再带 stf 形参。 ### 步骤 1:在 `tasks/` 下建 `kuaishou/` 子包 @@ -629,7 +624,6 @@ from . import task # noqa: F401 触发 @register_task 注册 ```python # tasks/__init__.py from .base import BaseTask, register_task, list_task_types, get_task_class -from .douyin import task # noqa: F401 from .generic import task # noqa: F401 from .kuaishou import task # noqa: F401 ← 新增这一行 ``` @@ -1029,7 +1023,7 @@ from .base import ACTIONS, ... # 1. 先建注册表 from . import like # 2. 再导入各 action,触发 @register_action ``` -`tasks/__init__.py` 同理:先 `from .base import BaseTask`,再 `from . import douyin`、`from . import generic`。 +`tasks/__init__.py` 同理:先 `from .base import BaseTask`,再 `from . import generic`(新增类型往下加)。 ### 10.2 中文输入 @@ -1130,7 +1124,7 @@ self.set_progress(videos_watched=5, round_idx=3) - [ ] 长循环内周期性调用 `self.heartbeat()` - [ ] `tasks//actions/__init__.py` 先 `from .base import ACTIONS` 再导入各 action - [ ] 每个 Action 有 `action_type` / `name` / `default_params` / `execute`,返回 `True/False` -- [ ] `Task.create_worker` 做 actions 参数级深合并(照抄抖音模板) +- [ ] `Task.create_worker` 做 actions 参数级深合并(照抄 `tasks/generic/task.py`) - [ ] `tasks/__init__.py` 已 `from . import task` 注册 - [ ] 日志用 `get_logger("task.")` / `get_logger("action..")`,无 `print` - [ ] 定位元素优先 `description` / `descriptionContains`,resourceId 多候选,xpath 用相对定位 diff --git a/static/admin/tasks.js b/static/admin/tasks.js index e48a696..7bc8bbf 100644 --- a/static/admin/tasks.js +++ b/static/admin/tasks.js @@ -69,7 +69,7 @@ function openTaskModal(jobId){ // 任务编辑器含步骤编辑,加宽弹窗;关闭时在 closeModal 移除 document.getElementById('modal-box').classList.add('wide-modal'); - const j=job||{name:'',task_type:'douyin_nurture',enabled:true,target:{mode:'all'},params:{},schedule:{mode:'once'},retry:{max_attempts:1,delay:60}}; + const j=job||{name:'',task_type:'generic_steps',enabled:true,target:{mode:'all'},params:{},schedule:{mode:'once'},retry:{max_attempts:1,delay:60}}; const tt=_taskTypes.map(t=>'').join(''); const gl=_groupsList.map(g=>'').join(''); const dl=_devicesList.map(s=>'').join(''); @@ -88,7 +88,7 @@ function openTaskModal(jobId){ document.getElementById('modal-body').innerHTML= '
'+ - '
'+ + '
'+ '
'+ '
'+ '
'+ diff --git a/tasks/__init__.py b/tasks/__init__.py index 5fcfded..97ba216 100644 --- a/tasks/__init__.py +++ b/tasks/__init__.py @@ -7,7 +7,7 @@ from .base import BaseTask, register_task, list_task_types, get_task_class # 导入所有任务包,触发 @register_task 注册 -from .douyin import task # noqa: F401 +# 当前只有一个任务类型:generic_steps(通用步骤,前端步骤编辑器编排) from .generic import task # noqa: F401 __all__ = ["BaseTask", "register_task", "list_task_types", "get_task_class"] diff --git a/tasks/base.py b/tasks/base.py index 568a67e..1f46061 100644 --- a/tasks/base.py +++ b/tasks/base.py @@ -12,7 +12,7 @@ base.py — 本任务的操作基类 + 注册器 xxx.py — 具体操作 -新增任务步骤(照着 tasks/douyin/ 抄即可): +新增任务步骤(照着 tasks/generic/ 抄即可): 1. 在 tasks/ 下新建 my_task/ 子包(文件夹 + __init__.py) 2. 在 my_task/task.py 顶部写默认参数: diff --git a/tasks/douyin/__init__.py b/tasks/douyin/__init__.py deleted file mode 100644 index eed26bc..0000000 --- a/tasks/douyin/__init__.py +++ /dev/null @@ -1,9 +0,0 @@ -"""抖音养号任务包。 - -本包自包含:任务定义(task.py)+ 抖音专属操作(actions/)。 -抖音的点赞/评论 xpath 只适用于抖音,不放全局,避免和其他任务混淆。 - -加新抖音操作:在 actions/ 下建 .py,继承本包 BaseAction + @register_action, -在 actions/__init__.py import。 -""" -from . import task # noqa: F401 触发 @register_task 注册抖音任务 diff --git a/tasks/douyin/actions/__init__.py b/tasks/douyin/actions/__init__.py deleted file mode 100644 index 7d9dd48..0000000 --- a/tasks/douyin/actions/__init__.py +++ /dev/null @@ -1,21 +0,0 @@ -"""抖音操作注册包。import 触发各操作注册。 - -加新抖音操作:新建 xxx.py,在下面加一行 from . import xxx。 -注意:必须先从 base 导入 ACTIONS,再导入各操作模块,否则循环导入。 -""" -# 先初始化注册表(base.py 里定义了 ACTIONS = create_action_registry()) -from .base import ( - BaseAction, register_action, create_action_registry, - list_actions, get_action, should_trigger, - ACTIONS, - list_action_types, get_action_class, -) - -# 再导入各操作模块,触发 @register_action(ACTIONS) 注册 -from . import like # noqa: F401 - -__all__ = [ - "BaseAction", "register_action", "create_action_registry", - "list_actions", "get_action", "should_trigger", - "ACTIONS", "list_action_types", "get_action_class", -] diff --git a/tasks/douyin/actions/base.py b/tasks/douyin/actions/base.py deleted file mode 100644 index 905e3f5..0000000 --- a/tasks/douyin/actions/base.py +++ /dev/null @@ -1,51 +0,0 @@ -"""抖音操作基类与注册机制。 - -操作 = 抖音养号主循环里某个时机执行的一次具体行为(点赞/评论/关注等)。 -这里的注册表只对抖音任务生效,其他任务有自己的 actions 包。 - -设计:抖音的 ACTIONS 注册表是独立的 dict,用 core.actions 的 -register_action(ACTIONS) 装饰器注册,和全局/其他 app 互不污染。 - -新增抖音操作步骤(照着 like.py 抄): - - 1. 在 tasks/douyin/actions/ 下新建 my_action.py - 2. 写一个 BaseAction 子类,用 @register_action 装饰,实现 execute: - - from core.actions import BaseAction, register_action, should_trigger - from . import ACTIONS # 本任务注册表 - - @register_action(ACTIONS) - class MyAction(BaseAction): - action_type = "my_action" - name = "我的操作" - description = "做什么" - default_params = {"rate": 0.5} - - def execute(self, d, params, worker): - if not should_trigger(params["rate"]): - return False - # ... 用 d(xpath=...) / d(text=...) 操作 - return True - - 3. 在 tasks/douyin/actions/__init__.py 加一行:from . import my_action - - 做完前端自动出现该操作的可勾选项。 -""" -from core.actions import ( - BaseAction, register_action, create_action_registry, - list_actions, get_action, should_trigger, -) - -# 抖音专属操作注册表(独立 dict,不污染其他 app) -ACTIONS = create_action_registry() - - -# 兼容旧导入:tasks/douyin/actions/__init__.py 原来从这里导出 -def list_action_types(): - """返回所有已注册抖音操作的元信息(供前端展示)。""" - return list_actions(ACTIONS) - - -def get_action_class(action_type): - """按 action_type 取抖音操作类。""" - return get_action(ACTIONS, action_type) diff --git a/tasks/douyin/actions/like.py b/tasks/douyin/actions/like.py deleted file mode 100644 index 1224196..0000000 --- a/tasks/douyin/actions/like.py +++ /dev/null @@ -1,108 +0,0 @@ -"""抖音点赞操作。 - -两种方式: - by_element — 用 xpath 找右侧红心按钮点击(相对定位,不依赖视频卡片序号) - double_click — 双击屏幕中央(需明确选择此方式,抖音"双击点赞"手势) - -by_element 找不到点赞按钮时**跳过本次,不点屏幕**(避免直播/无按钮页误触)。 -要适配新版本抖音:用 weditor 重新抓当前界面,调整下面定位逻辑。 -""" -from core.actions import BaseAction, register_action, should_trigger -from core.logger import get_logger -from . import ACTIONS - -_log = get_logger("action.like") - - -@register_action(ACTIONS) -class LikeAction(BaseAction): - action_type = "like" - name = "点赞" - description = "看完视频后随机点赞(找红心按钮,找不到回退双击)" - default_params = { - "rate": 0.3, # 触发概率 0~1 - "method": "by_element", # by_element=找红心 | double_click=双击屏幕 - } - - def execute(self, d, params, worker): - rate = float(params.get("rate", 0.3)) - if not should_trigger(rate): - return False - method = params.get("method", "by_element") - if method == "by_element": - if self._like_by_element(d): - worker.set_action("点赞(红心)") - return True - # 找不到点赞按钮:跳过本次,不点屏幕,避免误触(如直播/无点赞按钮的页面) - worker.set_action("点赞(未找到,跳过)") - return False - # 仅在明确选择 double_click 方式时才双击屏幕 - ok = self._double_click_center(d) - if ok: - worker.set_action("点赞(双击)") - return ok - - @staticmethod - def _like_by_element(d): - """找右侧操作栏红心按钮点击,成功返回 True。 - - 定位优先级:description 精确 → descriptionContains 模糊 → resourceId → xpath - 每种方式找到即点即返回,找不到继续下一种。全程记日志。 - """ - # 方式1:description 精确匹配(最稳,不依赖结构) - for desc in ("点赞", "未点赞", "like"): - el = d(description=desc) - if el.exists: - el.click() - _log.info(f"like 命中 description={desc}") - return True - # 方式2:descriptionContains 模糊匹配(适配不同版本文案) - for kw in ("赞", "like"): - el = d(descriptionContains=kw) - if el.exists: - el.click() - _log.info(f"like 命中 descriptionContains={kw}") - return True - # 方式3:resourceId 列表(扩充候选,覆盖更多抖音版本) - for rid in ("com.ss.android.ugc.aweme:id/aky", - "com.ss.android.ugc.aweme:id/d-like-view-icon", - "com.ss.android.ugc.aweme:id/h3r", - "com.ss.android.ugc.aweme:id/dfz", - "com.ss.android.ugc.aweme:id/c5w"): - el = d(resourceId=rid) - if el.exists: - el.click() - _log.info(f"like 命中 resourceId={rid}") - return True - # 方式4:xpath 相对定位——右侧操作栏 LinearLayout 的第一个 ImageView - # 定位思路:ViewPager 下当前 FrameLayout 里的 LinearLayout, - # 取其直接子 FrameLayout 里的第一个 ImageView(点赞在操作栏最上方) - try: - el = d.xpath( - '//androidx.viewpager.widget.ViewPager' - '/android.widget.FrameLayout' - '/com.bytedance.highperformanceview.layout.MeasureOnceRelativeLayout2' - '/com.bytedance.highperformanceview.layout.MeasureOnceRelativeLayout2' - '/android.widget.LinearLayout/android.widget.FrameLayout[2]' - '/android.widget.LinearLayout/android.widget.FrameLayout[1]' - '/android.widget.FrameLayout[1]/android.widget.ImageView' - ) - if el.exists: - el.click() - _log.info("like 命中 xpath") - return True - except Exception as e: - _log.warning(f"like xpath 异常: {e}") - _log.info("like_by_element 全部失败,准备回退双击") - return False - - @staticmethod - def _double_click_center(d): - """双击屏幕中央点赞。按屏幕尺寸算坐标,适配不同分辨率。""" - try: - info = d.info - w, h = info["displayWidth"], info["displayHeight"] - d.double_click(int(w * 0.5), int(h * 0.5)) - return True - except Exception: - return False diff --git a/tasks/douyin/task.py b/tasks/douyin/task.py deleted file mode 100644 index d24206f..0000000 --- a/tasks/douyin/task.py +++ /dev/null @@ -1,269 +0,0 @@ -"""抖音养号任务定义。 - -本文件自包含所有抖音养号参数(观看、滑动、操作等),不依赖 core 的业务配置。 -抖音专属操作(点赞/评论)在 actions/ 子包里,xpath 只适用于抖音。 - -修改养号行为:改下面 DEFAULT_PARAMS 默认值,或通过前端任务参数覆盖。 -修改养号逻辑:改 DouyinNurtureWorker.run_task。 -加新抖音操作:在 actions/ 下建 .py,继承 BaseAction + @register_action。 -""" -import time -import random - -from tasks.base import BaseTask, register_task -from .actions import list_action_types, get_action_class -from core.device_worker import BaseWorker, _update_status -from core.u2_helper import ensure_app_running, wait_for_app_home -from core.logger import get_logger - -_log = get_logger("task.douyin") - - -# ================== 抖音养号参数(本任务专属,写在这里) ================== -DOUYIN_PKG = "com.ss.android.ugc.aweme" - -DEFAULT_PARAMS = { - # 观看 - "watch_count": 80, # 观看视频数量(0=不限数量,仅按 max_duration 终止) - "watch_min": 5.0, # 单个视频最短观看秒数 - "watch_max": 35.0, # 单个视频最长观看秒数 - # 运行时长终止(通用,0=不限时,按 watch_count 终止) - # 两个条件哪个先到就停;都为 0 则永不停止(需手动停止) - "max_duration": 0, # 最大运行时长(秒),如 1800=30分钟,0=不限时 - # 滑动 - "swipe_min": 0.25, # 上滑手势最短时长(秒) - "swipe_max": 0.50, # 上滑手势最长时长(秒) - "gap_min": 1.0, # 视频间隔最短秒数 - "gap_max": 3.0, # 视频间隔最长秒数 - # 操作(每个操作有 enabled 开关 + 自身参数) - "actions": { - "like": { - "enabled": True, - "params": {"rate": 0.3, "method": "by_element"}, - }, - }, -} - - -class DouyinNurtureWorker(BaseWorker): - """抖音养号 worker:看视频 + 按配置执行操作(点赞/评论等),被退出自动重连。 - - 只需实现 run_task(d),STF 占用/释放、u2 连接、异常、状态上报由基类处理。 - 操作参数优先级:任务 params.actions > 本文件 DEFAULT_PARAMS.actions。 - """ - - def __init__(self, serial, params=None): - super().__init__(serial, params) - p = {**DEFAULT_PARAMS, **(self.params or {})} - self.watch_count = int(p["watch_count"]) - self.watch_min = float(p["watch_min"]) - self.watch_max = float(p["watch_max"]) - # 通用运行时长终止(0=不限时) - self.max_duration = int(p.get("max_duration", 0)) - self.swipe_min = float(p["swipe_min"]) - self.swipe_max = float(p["swipe_max"]) - self.gap_min = float(p["gap_min"]) - self.gap_max = float(p["gap_max"]) - # 操作配置:{action_type: {"enabled":bool, "params":{...}}} - self.actions_cfg = p.get("actions", {}) - # 实例化所有启用的操作 - self._actions = [] - for atype, cfg in self.actions_cfg.items(): - if not cfg.get("enabled"): - continue - cls = get_action_class(atype) - if cls: - self._actions.append(cls()) - # 启动日志:打印终止条件 + 启用的 action,便于排查 - stop_conds = [] - if self.watch_count > 0: - stop_conds.append(f"数量={self.watch_count}") - if self.max_duration > 0: - stop_conds.append(f"时长={self.max_duration}s") - if not stop_conds: - stop_conds.append("无(需手动停止)") - _log.info(f"[{serial}] 终止条件: {', '.join(stop_conds)}") - if self._actions: - summary = ", ".join( - f"{a.action_type}(rate={self.actions_cfg.get(a.action_type, {}).get('params', {}).get('rate', '?')})" - for a in self._actions - ) - _log.info(f"[{serial}] 启用操作: {summary}") - else: - _log.warning(f"[{serial}] 未启用任何操作,整个任务期间不会执行点赞") - - def run_task(self, d): - """抖音养号主逻辑。d 是 u2.Device,已由基类连好。 - - 终止条件(哪个先到就停): - - watch_count > 0:看完指定数量视频 - - max_duration > 0:达到最大运行时长 - - 两者都为 0:永不停止,需手动停止 - """ - def is_home(d): - return (d(descriptionContains="拍摄").exists - or d(descriptionContains="首页").exists) - - # 启动运行时长计时(基类通用方法) - self._start_timer() - - d.app_start(DOUYIN_PKG, wait=True) - if not wait_for_app_home(d, DOUYIN_PKG, is_home, timeout=40): - self.set_action("首页加载超时,继续尝试") - - watched = 0 - action_counts = {a.action_type: 0 for a in self._actions} - # 初始化通用进度上报 - # total=0 时前端不显示百分比,只显示已看数量 + 运行时长 - total = self.watch_count if self.watch_count > 0 else 0 - self.set_progress(done=0, total=total, unit="视频", - action_counts=action_counts) - while not self.stopped(): - # 终止条件检查 - if self.watch_count > 0 and watched >= self.watch_count: - break - if self.is_time_up(): - _log.info(f"[{self.serial}] 达到最大运行时长 {self.max_duration}s,停止") - break - - if not ensure_app_running(d, DOUYIN_PKG): - _update_status(self.serial, status="error", - last_error="抖音连续重启失败,放弃该设备") - return - _update_status(self.serial, douyin_running=True, last_error="") - - watch = random.uniform(self.watch_min, self.watch_max) - # 动作描述包含运行时长,便于前端观察 - elapsed = self.elapsed() - time_info = f",已运行 {elapsed//60}m{elapsed%60}s" if elapsed > 0 else "" - self.set_action(f"观看视频 {watched+1},{watch:.0f}s{time_info}") - time.sleep(watch) - - # 检测当前是否为可操作的正常视频页(有右侧操作栏 = 点赞/评论按钮) - # 营销广告、直播、异常页通常没有这些元素,直接滑过去不做操作 - is_normal = self._is_normal_video(d) - if is_normal: - # 正常视频:执行所有启用的操作(看完视频后、滑动前) - if not self._actions: - _log.info(f"[{self.serial}] 视频{watched+1}: 正常视频但无启用操作") - for action in self._actions: - if self.stopped(): - break - cfg = self.actions_cfg.get(action.action_type, {}) - params = {**action.default_params, **cfg.get("params", {})} - rate = params.get("rate", "?") - try: - ok = action.execute(d, params, self) - _log.info(f"[{self.serial}] 视频{watched+1}: {action.action_type} " - f"rate={rate} execute={ok}") - if ok: - action_counts[action.action_type] += 1 - time.sleep(random.uniform(0.5, 1.5)) - except Exception as e: - _log.error(f"[{self.serial}] 视频{watched+1}: 操作 {action.action_type} " - f"异常: {e}") - else: - self.set_action(f"跳过广告/直播 {watched+1}") - _log.info(f"[{self.serial}] 视频{watched+1}: 非正常视频页,跳过操作") - - if self.stopped(): - break - d.swipe(500, 1000, 500, 300, random.uniform(self.swipe_min, self.swipe_max)) - time.sleep(random.uniform(self.gap_min, self.gap_max)) - watched += 1 - # 上报通用进度(含运行时长,前端展示) - elapsed = self.elapsed() - self.set_progress(done=watched, total=total, unit="视频", - action_counts=dict(action_counts), - elapsed=elapsed) - - # 终止原因汇总 - stop_reason = "" - if self.stopped(): - stop_reason = "(手动停止)" - elif self.is_time_up(): - stop_reason = f"(达到时长 {self.max_duration}s)" - elif self.watch_count > 0 and watched >= self.watch_count: - stop_reason = f"(达到数量 {self.watch_count})" - summary = f"完成 {watched} 个视频" + "".join( - f",{k} {v}次" for k, v in action_counts.items() if v - ) + stop_reason - _update_status(self.serial, douyin_running=False, current_action=summary) - - @staticmethod - def _is_normal_video(d): - """判断当前是否为可操作的正常视频页。 - - 正常视频页右侧有操作栏(点赞/评论/分享按钮)。 - 营销广告、直播、异常页通常没有这些元素 → 返回 False,直接滑过去。 - 检测任一特征元素存在即认为是正常视频页。 - - 定位优先级:description 精确 → descriptionContains 模糊 → resourceId 列表 → 兜底 - 每次返回 False 时记日志,便于定位"为什么操作没执行"。 - """ - try: - # 1. description 精确匹配(最稳) - for desc in ("点赞", "未点赞", "评论", "未评论"): - if d(description=desc).exists: - return True - # 2. descriptionContains 模糊匹配(适配不同版本文案) - for kw in ("赞", "评论"): - if d(descriptionContains=kw).exists: - return True - # 3. resourceId 列表(扩充候选,覆盖更多抖音版本) - for rid in ("com.ss.android.ugc.aweme:id/aky", - "com.ss.android.ugc.aweme:id/akq", - "com.ss.android.ugc.aweme:id/d-like-view-icon", - "com.ss.android.ugc.aweme:id/d-comment-view-icon", - "com.ss.android.ugc.aweme:id/h3r"): - if d(resourceId=rid).exists: - return True - # 所有特征元素都没找到 → 非正常视频页(广告/直播/异常) - _log.info(f"_is_normal_video=False: 未找到点赞/评论特征元素") - return False - except Exception as e: - _log.warning(f"_is_normal_video 异常: {e}") - return False - - -@register_task -class DouyinNurtureTask(BaseTask): - """抖音养号:看视频 + 按配置执行操作(点赞/评论等),被退出自动重连。""" - task_type = "douyin_nurture" - name = "抖音养号" - description = "自动观看抖音视频,按配置执行点赞/评论等操作,被退出自动重连" - default_params = dict(DEFAULT_PARAMS) - - @classmethod - def list_action_types(cls): - """返回本任务支持的抖音操作列表。""" - return list_action_types() - - @classmethod - def get_action_class(cls, action_type): - """按 action_type 取抖音操作类。""" - return get_action_class(action_type) - - def create_worker(self, serial, params): - merged = {**DEFAULT_PARAMS, **(params or {})} - # actions 字段深合并(参数级,保留前端没传的操作默认值) - # 确保即使前端只传 actions.like.enabled,like.params.rate 也能拿到默认 0.3 - default_actions = DEFAULT_PARAMS["actions"] - merged_actions = params.get("actions", {}) if params else {} - for atype, dflt in default_actions.items(): - if atype not in merged_actions: - # 前端完全没传这个操作 → 用默认 - merged_actions[atype] = dflt - else: - # 前端传了 → 参数级深合并 - cfg = merged_actions[atype] - merged_cfg = {} - for k in ("enabled", "params"): - merged_cfg[k] = cfg.get(k, dflt.get(k)) - # params 再深合并一层 - merged_params = dict(dflt.get("params", {})) - merged_params.update(cfg.get("params", {})) - merged_cfg["params"] = merged_params - merged_actions[atype] = merged_cfg - merged["actions"] = merged_actions - return DouyinNurtureWorker(serial, params=merged) diff --git a/tasks/generic/__init__.py b/tasks/generic/__init__.py index 93b3f16..be7171b 100644 --- a/tasks/generic/__init__.py +++ b/tasks/generic/__init__.py @@ -1,6 +1,6 @@ """通用步骤任务包。 通过前端步骤编辑器编排任务流程,worker 按 steps 顺序执行。 -与 douyin_nurture 共存,互不影响。 +当前平台唯一的任务类型(task_type=generic_steps)。 """ from . import task # noqa: F401 触发 @register_task 注册通用步骤任务 diff --git a/tasks/generic/task.py b/tasks/generic/task.py index 6eb0b8f..f9dc50f 100644 --- a/tasks/generic/task.py +++ b/tasks/generic/task.py @@ -167,7 +167,7 @@ class GenericStepsWorker(BaseWorker): finally: elapsed = self.elapsed() summary = f"完成步骤链,运行 {elapsed//60}m{elapsed%60}s" - _update_status(self.serial, douyin_running=False, current_action=summary) + _update_status(self.serial, current_action=summary) def _exec_steps(self, d, steps, depth=0): """执行步骤列表。depth 防止无限嵌套。""" diff --git a/web/tasks_api.py b/web/tasks_api.py index f512e87..a9da591 100644 --- a/web/tasks_api.py +++ b/web/tasks_api.py @@ -106,7 +106,7 @@ def api_jobs_create(): name = (data.get("name") or "").strip() if not name: return jsonify({"ok": False, "error": "任务名不能为空"}), 400 - task_type = data.get("task_type", "douyin_nurture") + task_type = data.get("task_type", "generic_steps") if not get_task_class(task_type): return jsonify({"ok": False, "error": f"未知任务类型: {task_type}"}), 400 job = context.mgr.add_job(