fix: 评估任务正在取工参时补取任务一分钟后再来,不用等定时检查;工作区没就绪时把页面文字记进日志

This commit is contained in:
2026-11-12 12:43:03 +08:00
parent 3a7a5b39b4
commit 1c1ff6a0af
6 changed files with 54 additions and 11 deletions
+22
View File
@@ -89,6 +89,28 @@ def test_cache_status_counts_mondays_only(monkeypatch):
assert item["error"].startswith("2024-01-22 GongcanError: 平台出错") and item["errorAt"]
def test_execute_sync_chains_until_nothing_is_missing(monkeypatch):
requests = []
monkeypatch.setattr(gongcan_sync, "request_sync", lambda city, delay=0: requests.append((city, delay)))
monkeypatch.setattr(gongcan_sync, "has_valid_account", lambda: True)
outcomes = iter([(date(2024, 1, 22), 2), (None, 2), (date(2024, 1, 8), 0), (None, 0)])
monkeypatch.setattr(gongcan_sync, "sync_once", lambda city: next(outcomes))
for _ in range(4):
gongcan_sync.execute_sync(CITY)
# 取到一份还缺:马上接着排;别人正在取或在冷却:一分钟后再来;补齐了就不排。
assert requests == [(CITY, 0), (CITY, gongcan_sync.WAIT_SECONDS)]
def broken(city):
raise GongcanError("号池里没有可用的大数据平台账号")
monkeypatch.setattr(gongcan_sync, "sync_once", broken)
gongcan_sync.execute_sync(CITY)
monkeypatch.setattr(gongcan_sync, "sync_once", lambda city: (None, 5))
monkeypatch.setattr(gongcan_sync, "has_valid_account", lambda: False)
gongcan_sync.execute_sync(CITY)
assert len(requests) == 2
def test_request_sync_does_nothing_without_a_queue(monkeypatch):
monkeypatch.setattr(gongcan_sync, "postgres_conninfo", lambda: None)
assert gongcan_sync.request_sync("江门市") is False
+4
View File
@@ -225,6 +225,10 @@ def test_provision_gives_up_or_reports_expired_login():
looping = OpenCode(FakeNqi([Reply(307, "/pro-opencode/api/provision?x=1")]), poll_seconds=0, provision_wait=0)
with pytest.raises(OpenCodeError, match="没有跳转到工作区"):
asyncio.run(looping.provision())
page = Reply(200)
page.text = "<html><style>p{}</style><body><p>正在准备 工作区</p><a href='?token=ticket&t=TGT-123456-abcdef'>x</a> TGT-999999-zzzzzz</body></html>"
assert never._page_hint(page) == "正在准备 工作区 x <票据>"
assert never._page_hint(Reply(200)) == ""
class FakeSession(OpenCode):