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
+7 -1
View File
@@ -83,7 +83,7 @@ def _rate_from_group(group: dict[str, Any]) -> str:
"effective_rate_multiplier", "effectiveRateMultiplier",
"rate_multiplier", "rateMultiplier",
):
r = _decimal_str(group.get(key))
r = decimal_string(group.get(key))
if r:
return r
return ""
@@ -214,6 +214,12 @@ class UpstreamClient:
def close(self) -> None:
self._client.close()
def __enter__(self) -> UpstreamClient:
return self
def __exit__(self, *args: Any) -> None:
self.close()
def _url(self, path: str) -> str:
prefix = f"/{self.api_prefix}" if self.api_prefix else ""
return f"{self.base_url}{prefix}/{path.lstrip('/')}"