Merge branch 'dev' —— 全局切号参数生效修复
This commit is contained in:
+18
-2
@@ -85,6 +85,22 @@ DEFAULT_PROFILE = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def current_profile():
|
||||||
|
"""读 `ae_profile` 的**当前配置**并与默认值合并。
|
||||||
|
|
||||||
|
计划/调度在构建步骤时必须用这个,而不是 `merged()`(后者只看传入的 dict,
|
||||||
|
根本没读库)—— 否则页面「切号 / 发布前准备参数」里保存的全局值不会生效。
|
||||||
|
"""
|
||||||
|
from core.models import AeProfile
|
||||||
|
try:
|
||||||
|
with _ctx():
|
||||||
|
row = AeProfile.query.filter_by(id="default").first()
|
||||||
|
return merged(row.get_params() if row else None)
|
||||||
|
except Exception as e:
|
||||||
|
_log.debug("读取流水线配置失败(回落默认值): %s", e)
|
||||||
|
return merged()
|
||||||
|
|
||||||
|
|
||||||
def merged(profile=None):
|
def merged(profile=None):
|
||||||
"""把存下来的配置与默认值**深合并**(只补缺的键,用户填的优先)。"""
|
"""把存下来的配置与默认值**深合并**(只补缺的键,用户填的优先)。"""
|
||||||
def _deep(base, over):
|
def _deep(base, over):
|
||||||
@@ -2169,7 +2185,7 @@ def run_account_once(account, action_id="", profile=None, serial=None, date="",
|
|||||||
这里是**账号在外**(谁登着这个号谁跑),那里是**设备在外**(这台机器要跑哪几个号)。
|
这里是**账号在外**(谁登着这个号谁跑),那里是**设备在外**(这台机器要跑哪几个号)。
|
||||||
"""
|
"""
|
||||||
from core import video_plan as vp
|
from core import video_plan as vp
|
||||||
prof = merged(profile)
|
prof = merged(profile) if profile else current_profile()
|
||||||
date = (date or "").strip() or vp._today()
|
date = (date or "").strip() or vp._today()
|
||||||
run_id = (run_id or "").strip() or uuid.uuid4().hex[:12]
|
run_id = (run_id or "").strip() or uuid.uuid4().hex[:12]
|
||||||
if not serial:
|
if not serial:
|
||||||
@@ -2264,7 +2280,7 @@ def _run_with_serial(serial, accounts, action_id, profile, date, run_id=""):
|
|||||||
from core import video_plan as vp
|
from core import video_plan as vp
|
||||||
from core.models import AeRun, CustomAction, AeApp, db
|
from core.models import AeRun, CustomAction, AeApp, db
|
||||||
from tasks import get_task_class
|
from tasks import get_task_class
|
||||||
prof = merged(profile)
|
prof = merged(profile) if profile else current_profile()
|
||||||
date = (date or "").strip() or vp._today()
|
date = (date or "").strip() or vp._today()
|
||||||
run_id = (run_id or "").strip() or uuid.uuid4().hex[:12]
|
run_id = (run_id or "").strip() or uuid.uuid4().hex[:12]
|
||||||
started = _now()
|
started = _now()
|
||||||
|
|||||||
+4
-3
@@ -594,11 +594,12 @@ def build_plan_job(plan, device, plan_run_id=""):
|
|||||||
if segs:
|
if segs:
|
||||||
opts["segment_apps"] = seg_apps
|
opts["segment_apps"] = seg_apps
|
||||||
steps = af.build_segmented_steps(app_row.to_dict(), enriched,
|
steps = af.build_segmented_steps(app_row.to_dict(), enriched,
|
||||||
af.merged(), account=device["accounts"][0],
|
af.current_profile(),
|
||||||
opts=opts)
|
account=device["accounts"][0], opts=opts)
|
||||||
else:
|
else:
|
||||||
steps = af.build_run_steps(app_row.to_dict(), act.to_dict(),
|
steps = af.build_run_steps(app_row.to_dict(), act.to_dict(),
|
||||||
af.merged(), account=device["accounts"][0], opts=opts)
|
af.current_profile(),
|
||||||
|
account=device["accounts"][0], opts=opts)
|
||||||
try:
|
try:
|
||||||
miss_limit = max([int(e.get("miss_limit") or 0) for e in enriched] or [0])
|
miss_limit = max([int(e.get("miss_limit") or 0) for e in enriched] or [0])
|
||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
|
|||||||
@@ -1083,6 +1083,9 @@ A02 一度被记成 20.65(实际是 A11 的手机),自动认领把 A11 迁
|
|||||||
重试、登录页处置、切不过去处置——**所有计划默认共用**。
|
重试、登录页处置、切不过去处置——**所有计划默认共用**。
|
||||||
- `build_ready_step` 优先读全局 `fleet.switch`(再回落 `.env`);计划里的 `ready`
|
- `build_ready_step` 优先读全局 `fleet.switch`(再回落 `.env`);计划里的 `ready`
|
||||||
默认 `use_global=true`,**只有显式取消勾选「使用全局切号参数」才用本计划覆盖**。
|
默认 `use_global=true`,**只有显式取消勾选「使用全局切号参数」才用本计划覆盖**。
|
||||||
|
- **修了一个根因**:`build_plan_job` 以前传的是 `af.merged()`(只合并默认值、没读
|
||||||
|
`ae_profile`),所以页面保存的全局切号参数对计划根本不生效;现在改传
|
||||||
|
`af.current_profile()`(读库后合并)。`GET /api/af/ready_defaults` 同样改为读库。
|
||||||
- 老计划里存的整份选择器没有 `use_global` 字段 → 也按全局走;元素变了只改一次,
|
- 老计划里存的整份选择器没有 `use_global` 字段 → 也按全局走;元素变了只改一次,
|
||||||
不用逐个计划改。`clean_ready` 白名单增加 `use_global`。
|
不用逐个计划改。`clean_ready` 白名单增加 `use_global`。
|
||||||
- 测试:`test_plan.py` ②d(全局选择器生效 / 老计划仍用全局 / 显式覆盖);
|
- 测试:`test_plan.py` ②d(全局选择器生效 / 老计划仍用全局 / 显式覆盖);
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ os.chdir(sys.path[0])
|
|||||||
|
|
||||||
from flask import Flask # noqa: E402
|
from flask import Flask # noqa: E402
|
||||||
from core.models import (db, init_db, AeApp, CustomAction, TaskJob, # noqa: E402
|
from core.models import (db, init_db, AeApp, CustomAction, TaskJob, # noqa: E402
|
||||||
DeviceAccount, AePlan, AePlanRun)
|
DeviceAccount, AePlan, AePlanRun, AeProfile)
|
||||||
from core import account_folder as af # noqa: E402
|
from core import account_folder as af # noqa: E402
|
||||||
from core import device_pool, plan as plan_mod # noqa: E402
|
from core import device_pool, plan as plan_mod # noqa: E402
|
||||||
|
|
||||||
@@ -318,6 +318,31 @@ try:
|
|||||||
"name_selector_value": "//own"})["params"]
|
"name_selector_value": "//own"})["params"]
|
||||||
check("显式 use_global=false 才用本计划覆盖",
|
check("显式 use_global=false 才用本计划覆盖",
|
||||||
_own["name_selector_value"], "//own")
|
_own["name_selector_value"], "//own")
|
||||||
|
# 真正的计划构建必须读 ae_profile(以前 build_plan_job 传的是 merged() 默认值,
|
||||||
|
# 页面保存的全局切号参数根本不生效)
|
||||||
|
with app.app_context():
|
||||||
|
row = AeProfile.query.get("default")
|
||||||
|
if row is None:
|
||||||
|
row = AeProfile(id="default", name="测试配置", version=1)
|
||||||
|
db.session.add(row)
|
||||||
|
row.set_params({"fleet": {"switch": {
|
||||||
|
"entry_selector_type": "xpath", "entry_selector_value": "//db-entry",
|
||||||
|
"name_selector_type": "xpath", "name_selector_value": "//db-name",
|
||||||
|
"me_selector_type": "xpath", "me_selector_value": "//db-me"}}})
|
||||||
|
db.session.commit()
|
||||||
|
rp3 = {"id": "p8", "name": "读全局切号", "app_id": "app1", "accounts": ["号甲"],
|
||||||
|
"segments": [{"source": "action", "action_id": "act1", "app_id": "app1",
|
||||||
|
"name": "发布", "publish": True, "per_account": 1}],
|
||||||
|
"ready": {"enabled": True, "use_global": True}}
|
||||||
|
rj3, rerr3 = plan_mod.build_plan_job(
|
||||||
|
rp3, {"serial": "s", "device_name": "A07", "accounts": ["号甲"]})
|
||||||
|
check("计划构建读 ae_profile 不报错", rerr3, "")
|
||||||
|
_rd3 = [s for s in rj3.params["steps"][1]["params"]["children"]
|
||||||
|
if s["type"] == "ensure_account"][0]["params"]
|
||||||
|
check("计划构建用全局切号选择器",
|
||||||
|
(_rd3["switch_selector_value"], _rd3["name_selector_value"],
|
||||||
|
_rd3["me_selector_value"]),
|
||||||
|
("//db-entry", "//db-name", "//db-me"))
|
||||||
|
|
||||||
# ==================== ③ 计划 CRUD ====================
|
# ==================== ③ 计划 CRUD ====================
|
||||||
print("▶ ③ 计划保存 / 读 / 启停 / 删")
|
print("▶ ③ 计划保存 / 读 / 启停 / 删")
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ def api_af_ready_defaults():
|
|||||||
返回的就是 `build_ready_step()` 生成的 params:选择器、超时、切后等待、重试、登录页处置。
|
返回的就是 `build_ready_step()` 生成的 params:选择器、超时、切后等待、重试、登录页处置。
|
||||||
计划里保存的 `ready` 覆盖它;空 = 用这份默认。
|
计划里保存的 `ready` 覆盖它;空 = 用这份默认。
|
||||||
"""
|
"""
|
||||||
step = af.build_ready_step(af.merged()) or {}
|
step = af.build_ready_step(_profile_params()) or {}
|
||||||
return jsonify({"ok": True, "enabled": True, "params": step.get("params") or {}})
|
return jsonify({"ok": True, "enabled": True, "params": step.get("params") or {}})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user