fix: 评估任务正在取工参时补取任务一分钟后再来,不用等定时检查;工作区没就绪时把页面文字记进日志
This commit is contained in:
@@ -45,6 +45,7 @@ EFFECTIVE = ("eff_from_date", "eff_to_date")
|
||||
_NAME = re.compile(r"^[0-9A-Za-z_]{1,80}$")
|
||||
_FILENAME = re.compile(r"^[0-9A-Za-z_]{1,60}\.csv$")
|
||||
_SHELL_UNSAFE = ('"', "`", "$", "\\", "\n", "\r")
|
||||
_TICKET = re.compile(r"(?i)\b(?:TGT|ST|TGC)-[0-9A-Za-z_.\-]{6,}")
|
||||
_BASE62 = string.digits + string.ascii_letters
|
||||
|
||||
|
||||
@@ -315,11 +316,17 @@ class OpenCode:
|
||||
state = f"开通接口返回 {response.status_code},没有跳转到工作区"
|
||||
if state != seen:
|
||||
seen = state
|
||||
logger.info("OpenCode 工作区还没就绪:%s", state)
|
||||
logger.info("OpenCode 工作区还没就绪:%s %s", state, self._page_hint(response))
|
||||
if time.monotonic() >= deadline:
|
||||
raise OpenCodeError(f"平台没有为这个账号打开 AI 工作区({state})")
|
||||
await asyncio.sleep(self.poll_seconds)
|
||||
|
||||
def _page_hint(self, response) -> str:
|
||||
"""没跳转时页面上的文字开头,去掉标签和票据,写进日志方便看平台当时在做什么。"""
|
||||
text = re.sub(r"<(script|style)\b.*?</\1>|<[^>]+>", " ", str(getattr(response, "text", "") or ""), flags=re.S | re.I)
|
||||
text = _TICKET.sub("<票据>", text.replace(self.ticket, "<票据>") if self.ticket else text)
|
||||
return re.sub(r"\s+", " ", text).strip()[:160]
|
||||
|
||||
async def _call(self, method: str, path: str, *, params: dict | None = None, body: dict | None = None, tickets: bool = True) -> httpx.Response:
|
||||
if not self.base:
|
||||
raise OpenCodeError("还没有打开 AI 工作区")
|
||||
|
||||
Reference in New Issue
Block a user