mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-11 11:49:50 +08:00
修复重置次数缓存问题
This commit is contained in:
@@ -70,7 +70,7 @@ async fn gateway_refreshes_admin_provider_quota_locally_for_codex_with_trusted_a
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
let seen_execution_runtime = Arc::new(Mutex::new(None::<SeenExecutionRuntimeRequest>));
|
let seen_execution_runtime = Arc::new(Mutex::new(Vec::<SeenExecutionRuntimeRequest>::new()));
|
||||||
let seen_execution_runtime_clone = Arc::clone(&seen_execution_runtime);
|
let seen_execution_runtime_clone = Arc::clone(&seen_execution_runtime);
|
||||||
let execution_runtime = Router::new().route(
|
let execution_runtime = Router::new().route(
|
||||||
"/v1/execute/sync",
|
"/v1/execute/sync",
|
||||||
@@ -83,21 +83,22 @@ async fn gateway_refreshes_admin_provider_quota_locally_for_codex_with_trusted_a
|
|||||||
.expect("body should read"),
|
.expect("body should read"),
|
||||||
)
|
)
|
||||||
.expect("plan should parse");
|
.expect("plan should parse");
|
||||||
*seen_execution_runtime_inner
|
seen_execution_runtime_inner
|
||||||
.lock()
|
.lock()
|
||||||
.expect("mutex should lock") = Some(SeenExecutionRuntimeRequest {
|
.expect("mutex should lock")
|
||||||
url: plan.url.clone(),
|
.push(SeenExecutionRuntimeRequest {
|
||||||
authorization: plan
|
url: plan.url.clone(),
|
||||||
.headers
|
authorization: plan
|
||||||
.get("authorization")
|
.headers
|
||||||
.cloned()
|
.get("authorization")
|
||||||
.unwrap_or_default(),
|
.cloned()
|
||||||
provider_api_format: plan.provider_api_format.clone(),
|
.unwrap_or_default(),
|
||||||
total_ms: plan
|
provider_api_format: plan.provider_api_format.clone(),
|
||||||
.timeouts
|
total_ms: plan
|
||||||
.as_ref()
|
.timeouts
|
||||||
.and_then(|timeouts| timeouts.total_ms),
|
.as_ref()
|
||||||
});
|
.and_then(|timeouts| timeouts.total_ms),
|
||||||
|
});
|
||||||
let result = aether_contracts::ExecutionResult {
|
let result = aether_contracts::ExecutionResult {
|
||||||
request_id: plan.request_id,
|
request_id: plan.request_id,
|
||||||
candidate_id: None,
|
candidate_id: None,
|
||||||
@@ -223,24 +224,24 @@ async fn gateway_refreshes_admin_provider_quota_locally_for_codex_with_trusted_a
|
|||||||
);
|
);
|
||||||
assert_eq!(*upstream_hits.lock().expect("mutex should lock"), 0);
|
assert_eq!(*upstream_hits.lock().expect("mutex should lock"), 0);
|
||||||
|
|
||||||
let seen_execution_runtime_request = seen_execution_runtime
|
let seen_execution_runtime_requests = seen_execution_runtime
|
||||||
.lock()
|
.lock()
|
||||||
.expect("mutex should lock")
|
.expect("mutex should lock")
|
||||||
.clone()
|
.clone();
|
||||||
.expect("execution runtime request should be captured");
|
assert_eq!(seen_execution_runtime_requests.len(), 2);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
seen_execution_runtime_request.url,
|
seen_execution_runtime_requests[0].url,
|
||||||
"https://chatgpt.com/backend-api/wham/usage"
|
"https://chatgpt.com/backend-api/wham/usage"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
seen_execution_runtime_request.authorization,
|
seen_execution_runtime_requests[1].url,
|
||||||
"Bearer sk-codex-123"
|
"https://chatgpt.com/backend-api/wham/rate-limit-reset-credits"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
for request in seen_execution_runtime_requests {
|
||||||
seen_execution_runtime_request.provider_api_format,
|
assert_eq!(request.authorization, "Bearer sk-codex-123");
|
||||||
"openai:responses"
|
assert_eq!(request.provider_api_format, "openai:responses");
|
||||||
);
|
assert_eq!(request.total_ms, Some(30_000));
|
||||||
assert_eq!(seen_execution_runtime_request.total_ms, Some(30_000));
|
}
|
||||||
|
|
||||||
let reloaded = provider_catalog_repository
|
let reloaded = provider_catalog_repository
|
||||||
.list_keys_by_ids(&["key-codex-a".to_string()])
|
.list_keys_by_ids(&["key-codex-a".to_string()])
|
||||||
@@ -679,7 +680,10 @@ async fn gateway_refreshes_admin_provider_quota_locally_for_requested_codex_keys
|
|||||||
.lock()
|
.lock()
|
||||||
.expect("mutex should lock")
|
.expect("mutex should lock")
|
||||||
.clone(),
|
.clone(),
|
||||||
vec!["Bearer sk-codex-a".to_string()]
|
vec![
|
||||||
|
"Bearer sk-codex-a".to_string(),
|
||||||
|
"Bearer sk-codex-a".to_string(),
|
||||||
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
let reloaded = provider_catalog_repository
|
let reloaded = provider_catalog_repository
|
||||||
|
|||||||
@@ -2443,8 +2443,8 @@ function shouldAutoRefreshCodexQuota(): boolean {
|
|||||||
|
|
||||||
if (isTokenExpiringSoon(key, now)) return true
|
if (isTokenExpiringSoon(key, now)) return true
|
||||||
|
|
||||||
// 只要有一个活跃 key 没有配额数据,就刷新一次
|
// 旧缓存可能已有普通配额但没有 reset-credit 数据,仍需补拉一次
|
||||||
if (!hasCodexQuotaDisplayData(key)) {
|
if (!hasCodexQuotaDisplayData(key) || getCodexResetCreditAvailableCount(key) === null) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
// 配额数据超过 5 分钟未更新,也触发刷新
|
// 配额数据超过 5 分钟未更新,也触发刷新
|
||||||
|
|||||||
Reference in New Issue
Block a user