兜底
This commit is contained in:
+18
-2
@@ -117,13 +117,14 @@ class ServerAPI:
|
||||
resp.raise_for_status()
|
||||
return resp.json()
|
||||
|
||||
def heartbeat(self) -> bool:
|
||||
"""发送心跳,刷新服务端 last_seen_at;失败返回 False(不抛异常)"""
|
||||
def heartbeat(self, payload: dict | None = None) -> bool:
|
||||
"""发送心跳并携带 RPA 全量状态;失败返回 False(不抛异常)"""
|
||||
if not self.token:
|
||||
return False
|
||||
try:
|
||||
resp = self._req("post",
|
||||
f"{self.base_url}/api/auth/heartbeat",
|
||||
json=payload or {},
|
||||
headers=self._headers(), timeout=10,
|
||||
)
|
||||
return resp.status_code == 200
|
||||
@@ -131,6 +132,21 @@ class ServerAPI:
|
||||
logger.debug(f"心跳发送失败:{e}")
|
||||
return False
|
||||
|
||||
def fetch_pending_task(self) -> dict | None:
|
||||
"""轮询拉取待执行的远程控制任务(服务端已标记 running)"""
|
||||
resp = self._req("get", f"{self.base_url}/api/rpa/tasks/pending",
|
||||
headers=self._headers(), timeout=10)
|
||||
resp.raise_for_status()
|
||||
return resp.json().get("task")
|
||||
|
||||
def finish_task(self, task_id: int, status: str, result: str = "") -> None:
|
||||
"""远程任务执行完回调:更新终态与结果"""
|
||||
resp = self._req("post",
|
||||
f"{self.base_url}/api/rpa/tasks/{task_id}/finish",
|
||||
json={"status": status, "result": result[:500]},
|
||||
headers=self._headers(), timeout=10)
|
||||
resp.raise_for_status()
|
||||
|
||||
def update_login_status(self, status: str, boss_account: str | None = None) -> dict:
|
||||
payload = {"login_status": status}
|
||||
if boss_account:
|
||||
|
||||
Reference in New Issue
Block a user