mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
refactor(auth): replace NextRefreshAfter with NextRetryAfter for clarity and consistency
- Renamed field `NextRefreshAfter` to `NextRetryAfter` across `AuthManager`, `types`, and selector logic. - Updated references to ensure proper handling of retry timing logic. - Improved code readability and clarified retry behavior for different auth states.
This commit is contained in:
@@ -523,14 +523,14 @@ func (m *Manager) MarkResult(ctx context.Context, result Result) {
|
||||
switch statusCode {
|
||||
case 401:
|
||||
auth.StatusMessage = "unauthorized"
|
||||
auth.NextRefreshAfter = now.Add(30 * time.Minute)
|
||||
auth.NextRetryAfter = now.Add(30 * time.Minute)
|
||||
if result.Model != "" {
|
||||
shouldSuspendModel = true
|
||||
suspendReason = "unauthorized"
|
||||
}
|
||||
case 402, 403:
|
||||
auth.StatusMessage = "payment_required"
|
||||
auth.NextRefreshAfter = now.Add(30 * time.Minute)
|
||||
auth.NextRetryAfter = now.Add(30 * time.Minute)
|
||||
if result.Model != "" {
|
||||
shouldSuspendModel = true
|
||||
suspendReason = "payment_required"
|
||||
@@ -540,14 +540,14 @@ func (m *Manager) MarkResult(ctx context.Context, result Result) {
|
||||
auth.Quota.Exceeded = true
|
||||
auth.Quota.Reason = "quota"
|
||||
auth.Quota.NextRecoverAt = now.Add(30 * time.Minute)
|
||||
auth.NextRefreshAfter = auth.Quota.NextRecoverAt
|
||||
auth.NextRetryAfter = auth.Quota.NextRecoverAt
|
||||
if result.Model != "" {
|
||||
shouldSuspendModel = true
|
||||
registry.GetGlobalRegistry().SetModelQuotaExceeded(auth.ID, result.Model)
|
||||
}
|
||||
case 408, 500, 502, 503, 504:
|
||||
auth.StatusMessage = "transient upstream error"
|
||||
auth.NextRefreshAfter = now.Add(1 * time.Minute)
|
||||
auth.NextRetryAfter = now.Add(1 * time.Minute)
|
||||
if result.Model != "" {
|
||||
shouldSuspendModel = false
|
||||
suspendReason = "forbidden"
|
||||
|
||||
@@ -28,7 +28,7 @@ func (s *RoundRobinSelector) Pick(ctx context.Context, provider, model string, o
|
||||
now := time.Now()
|
||||
for i := range auths {
|
||||
candidate := auths[i]
|
||||
if candidate.Unavailable && candidate.Quota.NextRecoverAt.After(now) {
|
||||
if candidate.Unavailable && candidate.NextRetryAfter.After(now) {
|
||||
continue
|
||||
}
|
||||
if candidate.Status == StatusDisabled || candidate.Disabled {
|
||||
|
||||
@@ -43,6 +43,8 @@ type Auth struct {
|
||||
LastRefreshedAt time.Time `json:"last_refreshed_at"`
|
||||
// NextRefreshAfter is the earliest time a refresh should retrigger.
|
||||
NextRefreshAfter time.Time `json:"next_refresh_after"`
|
||||
// NextRetryAfter is the earliest time a retry should retrigger.
|
||||
NextRetryAfter time.Time `json:"next_retry_after"`
|
||||
|
||||
// Runtime carries non-serialisable data used during execution (in-memory only).
|
||||
Runtime any `json:"-"`
|
||||
|
||||
Reference in New Issue
Block a user