fix: remove stale _decimal_str ref, add context manager to HTTP clients

- UpstreamClient & Sub2ApiWebsiteClient: add __enter__/__exit__
- Convert all call sites to `with Client(...) as c:` pattern
- Remove unused `upstream_name`/`upstream_base_url` locals in scheduler
- Fix stale _decimal_str→decimal_string in _rate_from_group
This commit is contained in:
SmartUp Developer
2026-05-17 11:29:51 +08:00
parent 8a6ed249be
commit 2934473770
7 changed files with 104 additions and 93 deletions
+4 -2
View File
@@ -188,7 +188,8 @@ def test_website(wid: int, db: Session = Depends(get_db), _=Depends(get_current_
if not row:
raise HTTPException(404, "website not found")
try:
groups = _client(row).get_groups(row.groups_endpoint)
with _client(row) as c:
groups = c.get_groups(row.groups_endpoint)
row.last_status = "healthy"
row.last_error = None
row.last_checked_at = datetime.now(timezone.utc)
@@ -208,7 +209,8 @@ def list_website_groups(wid: int, db: Session = Depends(get_db), _=Depends(get_c
if not row:
raise HTTPException(404, "website not found")
try:
return _client(row).get_groups(row.groups_endpoint)
with _client(row) as c:
return c.get_groups(row.groups_endpoint)
except Exception as exc:
raise HTTPException(502, str(exc))