feat: 打开 browser_act

This commit is contained in:
Rocky Kwok committed 2026-06-24 15:40:56 +08:00
1 parent b1ef4ccb1a
commit 8ed54448c2
5 files changed
+106 -15

No files matched your search

@@ -193,16 +193,22 @@ def claim_next_browser_task(
user_id = str(user_id or "default")
worker_id = (worker_id or "chrome-extension").strip()[:128] or "chrome-extension"
lease_seconds = max(10, int(lease_seconds))
queue_dir = tasks_dir()
with _LOCK:
paths = sorted(tasks_dir().glob("*.json"), key=lambda p: p.stat().st_mtime)
paths = sorted(queue_dir.glob("*.json"), key=lambda p: p.stat().st_mtime)
matching_user = 0
matching_status_counts: dict[str, int] = {}
for path in paths:
data = _read_task(path)
if not data or str(data.get("user_id") or "") != user_id:
continue
matching_user += 1
data = _expire_if_needed(path, data, now)
status = data.get("status")
status_key = str(status or "unknown")
matching_status_counts[status_key] = matching_status_counts.get(status_key, 0) + 1
if status == "running":
updated_at = _parse_iso(data.get("updated_at")) or now
if (now - updated_at).total_seconds() <= lease_seconds:
@@ -220,8 +226,32 @@ def claim_next_browser_task(
data["claimed_at"] = _iso(now)
data["updated_at"] = _iso(now)
_write_task(path, data)
logger.info(
"Browser task claim scan user_id=%s worker_id=%s tasks_dir=%s total_files=%d matching_user=%d "
"matching_statuses=%s claimed_task_id=%s claimed_kind=%s",
user_id,
worker_id,
queue_dir,
len(paths),
matching_user,
matching_status_counts,
data.get("id"),
data.get("kind") or "fetch",
)
return _public_task(data)
logger.info(
"Browser task claim scan user_id=%s worker_id=%s tasks_dir=%s total_files=%d matching_user=%d "
"matching_statuses=%s claimed_task_id=%s claimed_kind=%s",
user_id,
worker_id,
queue_dir,
len(paths),
matching_user,
matching_status_counts,
None,
None,
)
return None
@@ -300,4 +330,3 @@ async def wait_for_browser_task_result(
if time.monotonic() >= deadline:
return task
await asyncio.sleep(interval)