fix: coordinate concurrent account capacity filling

This commit is contained in:
CoolBoy
2026-08-01 16:50:50 +08:00
parent c06169d906
commit 0cabc43abf
14 changed files with 794 additions and 143 deletions

View File

@@ -5,7 +5,7 @@ from datetime import datetime
from pathlib import Path
from typing import Any
from common import append_jsonl, ensure_utc, parse_datetime, read_jsonl, write_jsonl
from common import append_jsonl, ensure_utc, parse_datetime, read_jsonl, update_jsonl
WAITING_STATUSES = {"waiting", "queued"}
@@ -32,10 +32,10 @@ def update_history_archive(
*,
limit: int = HISTORY_ARCHIVE_LIMIT_DEFAULT,
) -> list[dict[str, Any]]:
merged = merge_history_records(load_history_archive(path), tasks, limit=limit)
path.parent.mkdir(parents=True, exist_ok=True)
write_jsonl(path, merged)
return merged
return update_jsonl(
path,
lambda existing: merge_history_records(existing, tasks, limit=limit),
)
def merge_history_records(