Compare commits
2
Commits
c0c955054c
...
ad7c7b69ee
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ad7c7b69ee | ||
|
|
6c1f241a16 |
+10
-1
@@ -507,6 +507,11 @@ def build_plan_job(plan, device, plan_run_id=""):
|
||||
e["steps"] = inline
|
||||
e["app_id"] = e.get("app_id") or _app_id_for_steps(inline)
|
||||
e["start_page"], e["end_page"] = {}, {}
|
||||
# 任务级「连续未命中」策略跟着任务段走进计划任务
|
||||
try:
|
||||
e["miss_limit"] = int(tj.get_params().get("miss_limit") or 0)
|
||||
except (TypeError, ValueError):
|
||||
e["miss_limit"] = 0
|
||||
else:
|
||||
aid = (s.get("action_id") or "").strip()
|
||||
a = CustomAction.query.get(aid)
|
||||
@@ -568,13 +573,17 @@ def build_plan_job(plan, device, plan_run_id=""):
|
||||
else:
|
||||
steps = af.build_run_steps(app_row.to_dict(), act.to_dict(),
|
||||
af.merged(), account=device["accounts"][0], opts=opts)
|
||||
try:
|
||||
miss_limit = max([int(e.get("miss_limit") or 0) for e in enriched] or [0])
|
||||
except (TypeError, ValueError):
|
||||
miss_limit = 0
|
||||
job = TaskJob(id="plan:%s" % plan["id"], name="计划·%s" % plan["name"],
|
||||
task_type="generic_steps",
|
||||
target={"mode": "serial", "serial": device["serial"]},
|
||||
params={"steps": steps, "accounts": device["accounts"],
|
||||
"dedup_reset": "day", "dedup_hours": 6,
|
||||
"preempt": bool(d.get("preempt")), "skip_offline": True,
|
||||
"max_duration": 0},
|
||||
"max_duration": 0, "miss_limit": miss_limit},
|
||||
schedule={"mode": "once"},
|
||||
retry=d.get("retry") or {"max_attempts": 1, "delay": 60},
|
||||
enabled=True)
|
||||
|
||||
@@ -756,3 +756,20 @@ data/accounts/周周苏州探店日记、周周苏州约会好去处/_日志/202
|
||||
- 新接口:`DELETE /api/af/account/<name>`(JSON 三个布尔值)。
|
||||
- 单测:建临时账号(文件夹 + 账号库 + 素材记录)→ 删除 → 目录归档、原文件仍在、
|
||||
账号库/记录清零。
|
||||
|
||||
## 23. 2026-10-18 新增:连续两次未命中就跳过本账号(`miss_limit`)
|
||||
|
||||
用户:"发布视频111…如果连续两次 miss 就直接跳过这个账号。"
|
||||
|
||||
以前 `click` 等步骤没命中只记一条 `miss`,**后面的步骤照样盲点**;现在加了任务级参数
|
||||
`miss_limit`(默认 0 = 不启用):
|
||||
|
||||
- 连续 `miss_limit` 个**叶子步骤**未命中 → 置 `_skip_rest`,**本账号剩余步骤不再执行**,
|
||||
账号循环自然换下一个号(与「校验页面」判不过走同一条收口)。
|
||||
- 中间任意一步成功(`ok`)→ 连续计数清零;容器步骤(`loop/group/if_el/foreach_*`、
|
||||
动作引用)不参与计数。
|
||||
- 每个账号 / 每条内容开始时清零。
|
||||
- 任务编辑器顶部多一个「连续未命中 N 步跳过本账号(0=不跳过)」;保存在任务
|
||||
`params.miss_limit`,计划里的**任务段**会把这个值带进计划任务。
|
||||
- 给「发布视频111」设 `miss_limit=2` 即用户要的效果。
|
||||
- 单测:`scripts/tests/test_miss_limit.py`(连续 miss 跳过、成功重置、0=关闭)。
|
||||
|
||||
@@ -99,6 +99,10 @@ from .generic import task # 触发 @register_task(当前唯一任务类型)
|
||||
|
||||
- **任务级参数**:`DEFAULT_PARAMS = {"max_duration": 0, "dedup_reset": "day", "dedup_hours": 6}`
|
||||
(`max_duration` 0 = 不限时;`dedup_reset` 是去重有效期,见 §4.6)
|
||||
- **`miss_limit`(默认 0 = 不启用)**:连续 N **个叶子步骤**未命中(`miss`)就置
|
||||
`_skip_rest`,**本账号剩余步骤不再执行**,由账号循环换下一个号;中间任意一步成功会
|
||||
重新计数。任务编辑器顶部可填(「连续未命中 N 步跳过本账号」)。计划里的**任务段**
|
||||
会把任务的 `miss_limit` 带进计划任务(见 `core/plan.py::build_plan_job`)。
|
||||
- **没有默认步骤**:`steps` 只能由编辑器产出;为空时 worker 立即报错「通用步骤任务没有可执行步骤:请在「任务」页编辑该任务并添加步骤」(设备「最近错误」可见),**不会静默空跑**
|
||||
- **顶层 steps 只顺序执行一次**——需要重复的动作必须显式放进 `loop` 步骤
|
||||
- **每步 schema**:`{id, type, label, params}`;`id` 由前端生成保证唯一(导出为自定义动作时会剥掉 id)
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
test_plan 计划调度:选账号→现算设备、每人限 N 条、计划 CRUD、时间点→cron、运行收尾
|
||||
test_action_ref 动作引用:执行时现展开、循环引用挡住、引用扫描(谁在用)、删除保护、摊平逃生口
|
||||
test_assets 资产管理:模板导入(两项校验/分拣/去重/音频)、指定素材、编辑元数据、共享文件删除
|
||||
test_miss_limit 连续未命中:连续 N 步 miss 跳过本账号,成功一次重新计数
|
||||
"""
|
||||
import os
|
||||
import subprocess
|
||||
@@ -35,7 +36,7 @@ CASES = ["test_parse_name.py", "test_upload_name.py", "test_name_scope.py",
|
||||
"test_switch_account.py", "test_foreach_account.py", "test_push_by_name.py",
|
||||
"test_expect_el.py", "test_read_text.py", "test_account_folder.py",
|
||||
"test_task_try.py", "test_roster.py", "test_plan.py",
|
||||
"test_action_ref.py", "test_assets.py"]
|
||||
"test_action_ref.py", "test_assets.py", "test_miss_limit.py"]
|
||||
|
||||
if hasattr(sys.stdout, "reconfigure"):
|
||||
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""连续未命中策略:连续 N 步 miss → 跳过本账号剩余步骤。
|
||||
|
||||
不连 adb、不连真机:步骤用的是测试里挂上去的假 handler。
|
||||
"""
|
||||
import io
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
|
||||
os.environ['DATABASE_URL'] = 'sqlite:///:memory:'
|
||||
os.environ['DEPLOY_ENV'] = 'dev'
|
||||
os.environ['DB_ALLOW_SQLITE_FALLBACK'] = '1'
|
||||
_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
sys.path.insert(0, _ROOT)
|
||||
os.chdir(_ROOT)
|
||||
|
||||
from tasks.generic import task as gt # noqa: E402
|
||||
|
||||
fails = []
|
||||
|
||||
|
||||
def check(label, got, want):
|
||||
ok = got == want
|
||||
if not ok:
|
||||
fails.append(label)
|
||||
print((' ✅ ' if ok else ' ❌ ') + label + ('' if ok else '\n 得到 %r\n 期望 %r' % (got, want)))
|
||||
|
||||
|
||||
def step(name, ok):
|
||||
return {"type": "fake", "label": name, "params": {"name": name, "ok": ok}}
|
||||
|
||||
|
||||
def run(steps, miss_limit):
|
||||
w = gt.GenericStepsWorker("M1", {"miss_limit": miss_limit})
|
||||
calls = []
|
||||
|
||||
def fake(d, params, depth=0):
|
||||
calls.append(params.get("name"))
|
||||
return params.get("ok")
|
||||
|
||||
w._exec_fake = fake
|
||||
w._exec_steps(None, steps)
|
||||
return calls, w
|
||||
|
||||
|
||||
print('=== 1. 连续 2 次 miss → 跳过本账号剩余步骤 ===')
|
||||
calls, w = run([step('a', False), step('b', False), step('c', True)], 2)
|
||||
check('a、b 执行了,c 没执行', calls, ['a', 'b'])
|
||||
check('置位 skip_rest', w._skip_rest, True)
|
||||
|
||||
print('=== 2. 中间成功一次会重新计数 ===')
|
||||
calls, w = run([step('a', False), step('b', True), step('c', False),
|
||||
step('d', False), step('e', True)], 2)
|
||||
check('成功之前的 miss 不算连续', calls, ['a', 'b', 'c', 'd'])
|
||||
|
||||
print('=== 3. 不连续 miss 不触发 ===')
|
||||
calls, w = run([step('a', False), step('b', True), step('c', False)], 2)
|
||||
check('三步都执行', calls, ['a', 'b', 'c'])
|
||||
check('没有置位 skip_rest', w._skip_rest, False)
|
||||
|
||||
print('=== 4. miss_limit=0(默认)不启用 ===')
|
||||
calls, w = run([step('a', False), step('b', False), step('c', False)], 0)
|
||||
check('全部执行', calls, ['a', 'b', 'c'])
|
||||
check('没有置位 skip_rest', w._skip_rest, False)
|
||||
|
||||
print()
|
||||
if fails:
|
||||
print('❌ 失败 %d 项:%s' % (len(fails), ' / '.join(fails)))
|
||||
sys.exit(1)
|
||||
print('✅ 全部通过(未连任何真机)')
|
||||
@@ -183,7 +183,7 @@ try:
|
||||
# ==================== ②c 任务段:只取任务步骤 ====================
|
||||
print("▶ ②c 计划里直接用任务:只取步骤,拆掉外层账号循环")
|
||||
db.session.add(TaskJob(id="job1", name="发布任务111", task_type="generic_steps",
|
||||
params=json.dumps({"steps": [
|
||||
params=json.dumps({"miss_limit": 2, "steps": [
|
||||
{"type": "screen_on", "label": "亮屏", "params": {}},
|
||||
{"type": "foreach_account", "label": "循环账号",
|
||||
"params": {"children": [
|
||||
@@ -206,6 +206,7 @@ try:
|
||||
task_job, task_err = plan_mod.build_plan_job(
|
||||
task_plan, {"serial": "s", "device_name": "A07", "accounts": ["号甲"]})
|
||||
check("任务段构建不报错", task_err, "")
|
||||
check("任务段的 miss_limit 带进计划任务", task_job.params.get("miss_limit"), 2)
|
||||
task_kids = task_job.params["steps"][1]["params"]["children"]
|
||||
check("任务段外层账号循环被拆掉(不再套一层)",
|
||||
any(s["type"] == "foreach_account" for s in task_kids), False)
|
||||
|
||||
+12
-1
@@ -193,6 +193,14 @@ var _stepEditor={
|
||||
md.innerHTML='运行时长上限(秒,0=不限) <input type="number" id="f-max_duration" value="'+(maxDuration||0)+'" min="0" style="width:70px;padding:2px 6px;border:1px solid var(--border);border-radius:4px;font-size:12px">';
|
||||
head.appendChild(md);
|
||||
}
|
||||
// 连续未命中策略(任务级):连续 N 步没命中就跳过本账号,0=不启用
|
||||
var mlExtra=taskExtra||{};
|
||||
if(head&&!document.getElementById('f-miss_limit')){
|
||||
var ml=document.createElement('span');
|
||||
ml.style.cssText='font-size:11px;display:flex;align-items:center;gap:4px';
|
||||
ml.innerHTML='连续未命中 <input type="number" id="f-miss_limit" value="'+(parseInt(mlExtra.miss_limit)||0)+'" min="0" max="9" style="width:56px;padding:2px 6px;border:1px solid var(--border);border-radius:4px;font-size:12px"> 步跳过本账号(0=不跳过)';
|
||||
head.appendChild(ml);
|
||||
}
|
||||
// 去重有效期(任务级):**只在这一处配**——「条件判断→去重」和「记为已做」两处
|
||||
// 各填一份的话,填不一致就会算出两个不同的 key、去重静默失效,所以强制共用。
|
||||
var drHost=document.querySelector('#step-editor .se-head');
|
||||
@@ -1726,7 +1734,10 @@ async function saveTask(jobId){
|
||||
if(!confirm('步骤配置有问题:\n\n'+warnings.join('\n')+'\n\n确定要保存吗?'))return;
|
||||
}
|
||||
const mdEl=document.getElementById('f-max_duration');
|
||||
params={max_duration:mdEl?parseInt(mdEl.value)||0:0,steps:steps};
|
||||
const mlEl=document.getElementById('f-miss_limit');
|
||||
params={max_duration:mdEl?parseInt(mdEl.value)||0:0,
|
||||
miss_limit:mlEl?Math.max(0,parseInt(mlEl.value)||0):0,
|
||||
steps:steps};
|
||||
// 去重有效期(任务级;「条件判断→去重」与「记为已做」共用这一套)
|
||||
const drEl=document.getElementById('f-dedup_reset');
|
||||
params.dedup_reset=drEl?drEl.value:'day';
|
||||
|
||||
@@ -669,7 +669,8 @@ function openTaskModal(jobId, prefill){
|
||||
// 这样"谁在用这个组合"才查得出来(删组合前的引用提示,见 core/action_ref.py)。
|
||||
// 老任务里已经展开的副本不受影响;画布上任一引用节点都能「转为快照展开」脱钩单独改。
|
||||
_stepEditor.init(j.params&&j.params.steps?j.params.steps:[],j.params&&j.params.max_duration?j.params.max_duration:0,draftKey,
|
||||
null,null,{dedup_reset:(j.params&&j.params.dedup_reset)||'day',dedup_hours:(j.params&&j.params.dedup_hours)||6},
|
||||
null,null,{dedup_reset:(j.params&&j.params.dedup_reset)||'day',dedup_hours:(j.params&&j.params.dedup_hours)||6,
|
||||
miss_limit:(j.params&&j.params.miss_limit)||0},
|
||||
{refActions:true});
|
||||
patrolInit(j.params&&j.params.watchers);
|
||||
|
||||
|
||||
@@ -298,6 +298,9 @@ class GenericStepsWorker(BaseWorker):
|
||||
self.steps = p.get("steps", [])
|
||||
self._action_counts = {} # 步骤执行计数 {step_label: count}
|
||||
self._miss_counts = {} # 选择器健康:selector -> 连续未命中次数
|
||||
# 连续未命中策略(任务级 `miss_limit`,0=不启用):
|
||||
# 连续 N 步没命中就置 `_skip_rest` → 本账号剩余步骤不再执行,换下一个号。
|
||||
self._miss_streak = 0
|
||||
# 步骤路径:容器步骤(loop/group/if_el)进出时压栈,得到 "2.1.3" 这种位置,
|
||||
# 写进「步骤明细」用来还原嵌套结构。worker 每台设备一个线程,实例级状态安全。
|
||||
self._path = []
|
||||
@@ -449,6 +452,25 @@ class GenericStepsWorker(BaseWorker):
|
||||
_log.warning(f"[{self.serial}] 未知步骤类型: {stype}")
|
||||
result, detail = "unknown", f"未知步骤类型: {stype}"
|
||||
self._record_step(step, result, detail, int((time.time() - t0) * 1000))
|
||||
# 连续未命中:连续 `miss_limit` 步没命中 → 跳过本账号剩余步骤。
|
||||
# 只在**叶子操作**上累计/复位;容器步骤的返回值不代表命中(它的子步骤
|
||||
# 自己会走这里),否则会把刚攒起来的连续 miss 冲掉。
|
||||
_CONTAINERS = ("loop", "group", "if_el", "foreach_account",
|
||||
"foreach_item", "action_ref")
|
||||
if stype not in _CONTAINERS:
|
||||
if result == "miss":
|
||||
self._miss_streak += 1
|
||||
try:
|
||||
_limit = int(self.params.get("miss_limit") or 0)
|
||||
except (TypeError, ValueError):
|
||||
_limit = 0
|
||||
if _limit > 0 and self._miss_streak >= _limit:
|
||||
_log.warning(
|
||||
f"[{self.serial}] 连续 {self._miss_streak} 步未命中(miss_limit={_limit})"
|
||||
f" → 跳过本账号剩余步骤,换下一个号")
|
||||
self._skip_rest = True
|
||||
elif result == "ok":
|
||||
self._miss_streak = 0
|
||||
# 容器步骤(loop/group/if_el/foreach_account)不计入操作计数,避免监控显示噪音
|
||||
if stype not in ("loop", "group", "if_el", "foreach_account", "action_ref"):
|
||||
self._action_counts[label] = self._action_counts.get(label, 0) + 1
|
||||
@@ -2226,6 +2248,7 @@ class GenericStepsWorker(BaseWorker):
|
||||
self.set_action(f"发这个号的一条内容(第 {done + 1} 条:#{plan.get('seq')})")
|
||||
_log.info(f"[{self.serial}] 内容循环:『{target}』第 {done + 1} 条"
|
||||
f"({date} #{plan.get('seq')} {plan.get('title') or '(无标题)'})")
|
||||
self._miss_streak = 0 # 每条内容重新计连续未命中
|
||||
self._exec_steps(d, children, depth + 1)
|
||||
done += 1
|
||||
if self._break_loop: # 子步骤里有「跳出循环」→ 这个号的内容循环结束
|
||||
@@ -2295,6 +2318,7 @@ class GenericStepsWorker(BaseWorker):
|
||||
self._vars["target_name"] = target
|
||||
self.set_account(target) # 运行监测的"当前账号"
|
||||
self._skip_rest = False # 新一轮:复位"跳过剩余步骤"(上一轮某步判过页面不对)
|
||||
self._miss_streak = 0 # 新账号:连续未命中计数从 0 开始
|
||||
sent += 1
|
||||
self.set_action(f"第 {sent} 个号:{target}(本机还有 {len(names)} 个待发名字)")
|
||||
_log.info(f"[{self.serial}] 循环本机待发的号:轮到『{target}』"
|
||||
@@ -2395,6 +2419,7 @@ class GenericStepsWorker(BaseWorker):
|
||||
self.set_action(f"发这个号的一条内容(第 {done + 1} 条:#{plan.get('seq')})")
|
||||
_log.info(f"[{self.serial}] 内容循环:『{target}』第 {done + 1} 条"
|
||||
f"({date} #{plan.get('seq')} {plan.get('title') or '(无标题)'})")
|
||||
self._miss_streak = 0 # 每条内容重新计连续未命中
|
||||
self._exec_steps(d, children, depth + 1)
|
||||
done += 1
|
||||
if self._break_loop: # 子步骤里有「跳出循环」→ 这个号的内容循环结束
|
||||
@@ -2464,6 +2489,7 @@ class GenericStepsWorker(BaseWorker):
|
||||
self._vars["target_name"] = target
|
||||
self.set_account(target) # 运行监测的"当前账号"
|
||||
self._skip_rest = False # 新一轮:复位"跳过剩余步骤"(上一轮某步判过页面不对)
|
||||
self._miss_streak = 0 # 新账号:连续未命中计数从 0 开始
|
||||
sent += 1
|
||||
self.set_action(f"第 {sent} 个号:{target}(本机还有 {len(names)} 个待发名字)")
|
||||
_log.info(f"[{self.serial}] 循环本机待发的号:轮到『{target}』"
|
||||
|
||||
Reference in New Issue
Block a user