fix(计划): 定时触发补 app context;账号状态加检测时间与历史记录
- _fire 内调用 run_plan(修复 18:00 Working outside application context,无运行记录) - device_account 新增 status_checked_at;新表 account_status_log(schema v23) - 每次检测/手改留痕;资产表显示检测时间 + 「记录」弹窗 - API /api/af/account_status_logs;备份标签/文档/测试同步
This commit is contained in:
+27
-7
@@ -173,6 +173,7 @@ def list_accounts(prof=None):
|
||||
"has_dir": has_dir,
|
||||
"device_name": rr.get("device_name") or "",
|
||||
"account_status": rr.get("account_status") or "",
|
||||
"status_checked_at": rr.get("status_checked_at") or "",
|
||||
"serial": rr.get("serial") or "",
|
||||
"pooled": bool(rr.get("pooled")),
|
||||
"online": bool(rr.get("online")),
|
||||
@@ -1144,24 +1145,43 @@ def roster_rows():
|
||||
return out
|
||||
|
||||
|
||||
def set_account_status(name, status=""):
|
||||
"""按账号名写账号库的「账号状态」(任务变量回写用)。
|
||||
def set_account_status(name, status="", source="", run_id=""):
|
||||
"""按账号名写账号库的「账号状态」,并追加一条检测记录。
|
||||
|
||||
名字先精确匹配昵称,再按抖音号兜底;账号库里没有这个号 → 返回 False(**不新建行**)。
|
||||
供任务里的「读取文字」在变量名是 `account_status` 时调用:读到什么写什么,
|
||||
读不到(元素不存在)写「正常」。
|
||||
供任务里的「读取文字」在变量名是 `account_status` 时调用:读到什么写什么;
|
||||
读不到时调用方不调用(保留原值)。同一 `run_id` + 账号只留一条记录
|
||||
(一次运行里重复写时更新那一条,不刷重复历史)。
|
||||
"""
|
||||
from core.models import db, DeviceAccount
|
||||
from core.models import db, DeviceAccount, AccountStatusLog
|
||||
key = (name or "").strip()
|
||||
if not key:
|
||||
return False
|
||||
now = _now()
|
||||
val = (status or "").strip()[:80]
|
||||
with _ctx():
|
||||
row = (DeviceAccount.query.filter_by(nickname=key).first()
|
||||
or DeviceAccount.query.filter_by(douyin_id=key).first())
|
||||
if row is None:
|
||||
return False
|
||||
row.account_status = (status or "").strip()[:80]
|
||||
row.updated_at = _now()
|
||||
row.account_status = val
|
||||
row.status_checked_at = now
|
||||
row.updated_at = now
|
||||
log = None
|
||||
if run_id:
|
||||
log = AccountStatusLog.query.filter_by(
|
||||
nickname=row.nickname, run_id=str(run_id)[:32]).first()
|
||||
if log is not None:
|
||||
log.status = val
|
||||
log.detected_at = now
|
||||
log.device_name = row.device_name or log.device_name
|
||||
else:
|
||||
db.session.add(AccountStatusLog(
|
||||
id=uuid.uuid4().hex[:8], account_id=row.id,
|
||||
nickname=row.nickname, device_name=row.device_name or "",
|
||||
serial=row.serial or "", status=val,
|
||||
source=(source or "")[:40], run_id=str(run_id or "")[:32],
|
||||
detected_at=now, created_at=now))
|
||||
db.session.commit()
|
||||
return True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user